Other methods

There are some other methods in the adjoe SDK which you might find helpful.

name

description

getVersion

Returns the internal version code of the adjoe SDK, for example 70.

getVersionName

Returns the version name of the adjoe SDK, for example 2.1.1

hasAcceptedTOS

Returns true if the user has accepted the adjoe TOS and false otherwise.

Payout via SDK

The following information on SDK-side reward handling is only relevant for your integration if you cannot use Server-to-Server Payout. Do not implement these functions if you already successfully followed the steps in the Payout section - it could trigger error messages and unexpected behaviour.

If you cannot handle the payout requests via an endpoint on your server, we can also handle the reward payouts inside the SDK itself.

To pay out the rewards that the user has collected from partner apps directly in the SDK, call

try {
    Adjoe.doPayout(context, new AdjoePayoutListener() {

        @Override
        public void onPayoutExecuted(int rewards) {
            // rewards is the amount of `rewards` that have been 
            // successfully withdrawn from the balance
        }

        @Override
        public void onPayoutError(AdjoePayoutError adjoePayoutError) {
            // an error occurred while paying out the rewards

            // get information about why it failed
            // 'reason' is one of
            //  - AdjoePayoutError.UNKNOWN
            //  - AdjoePayoutError.NOT_ENOUGH_COINS
            //  - AdjoePayoutError.TOS_NOT_ACCEPTED
            int reason = adjoePayoutError.getReason();

            // if available, get more information about the error
            if (error.getException() != null) {
                error.getException().printStackTrace();
            }
        }
    });
} catch(AdjoeNotInitializedException e) {
    // make sure to initialize the adjoe SDK first
}

This method always pays out all rewards which the user has collected, i.e. the value of AdjoeRewardResponse.getAvailablePayoutCoins().

If the user has not accepted the adjoe Terms of Service yet, this operation will fail and reason will be equal to AdjoePayoutError.TOS_NOT_ACCEPTED. You might want to forward to Playtime again so that the user can accept the adjoe Terms of Service. This operation will also fail with reason equal to AdjoePayoutError.UNKNOWN if the user is blocked by the adjoe services.

Adjoe Parameters

You can pass additional UA and placement parameters when you pay out the rewards:

AdjoeParams adjoeParams = new AdjoeParams.Builder()
                .setUaNetwork("network")
                .setUaChannel("channel")
                .setUaSubPublisherCleartext("SubPublisherCleartext")
                .setUaSubPublisherEncrypted("SubPublisherEncrypted")
                .setPlacement("placement")
                .build();
Adjoe.doPayout(context, adjoeParams, listener)

Retrying the payout

Sometimes, it can happen that the latest rewards haven't been processed yet by the server when you pay out. In this case, the onPayoutError function would be invoked with reason equal to AdjoePayoutError.NOT_ENOUGH_COINS. To overcome this, you can implement a retry mechanism for the payout, for example with an exponential backoff.

Example:

private static final long PAYOUT_RETRY_BASE = 2000;
private static final long PAYOUT_RETRY_MULTIPLIER = 2;
private static final int MAX_PAYOUT_RETRIES = 5;
private static final Handler ADJOE_PAYOUT_HANDLER = new Handler();

public void doAdjoePayout() {
    doAdjoePayoutInternal(0);
}

private void doAdjoePayoutInternal(int times) {
    if (times < 0 || times >= MAX_PAYOUT_RETRIES) {
        // the payout has failed too often, which means that the user has no coins
        // you should handle this case properly
        return;
    }

    Adjoe.doPayout(context, new AdjoePayoutListener() {

        @Override
        public void onPayoutExecuted(int coins) {
            // everything is fine, coins have been paid out
        } 

        @Override
        public void onPayoutError(AdjoePayoutError error) {
            if (error.getReason() == AdjoePayoutError.NOT_ENOUGH_COINS) {
                ADJOE_PAYOUT_HANDLER.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        doAdjoePayoutInternal(times + 1);
                    }
                }, PAYOUT_RETRY_BASE * Math.pow(PAYOUT_RETRY_MULiTIPLiER, times));
            }
        }
    });
}

Further Context on Rewards

You can get information about the rewards that the user has collected as well as about how many rewards are available for payout and how many the user has already spent.

To do so call

try {
    Adjoe.requestRewards(context, new AdjoeRewardListener() {

        @Override
        public void onUserReceivesReward(AdjoeRewardResponse adjoeRewardResponse) {
            // successfully requested the rewards

            // get how many rewards the user has collected
            int reward = adjoeRewardResponse.getReward();

            // get how many rewards are available for payout
            int availableForPayout = adjoeRewardResponse.getAvailablePayoutCoins();

            // get how many rewards the user has already spent
            int alreadySpentCoins = adjoeRewardResponse.getAlreadySpentCoins();
        }

        @Override
        public void onUserReceivesRewardError(AdjoeRewardResponseError adjoeRewardResponseError) {
            // an error occurred while requesting the rewards

            // you can try to get additional information about the error for debugging
            if (adjoeRewardResponseError.getException() != null) {
                adjoeRewardResponseError.getException().printStackTrace();
            }
        }
    });
} catch (AdjoeNotInitializedException e) {
    // make sure to initialize the adjoe SDK first
}

This operation will fail if the user has not accepted the adjoe Terms of Service or is blocked by the adjoe services.

Adjoe Parameters

You can pass additional UA and placement parameters when you request the rewards:

AdjoeParams adjoeParams = new AdjoeParams.Builder()
                .setUaNetwork("network")
                .setUaChannel("channel")
                .setUaSubPublisherCleartext("SubPublisherCleartext")
                .setUaSubPublisherEncrypted("SubPublisherEncrypted")
                .setPlacement("placement")
                .build();
Adjoe.requestRewards(context, adjoeParams, listener);

Last updated