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.0
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() {@Overridepublic void onPayoutExecuted(int rewards) {// rewards is the amount of `rewards` that have been // successfully withdrawn from the balance }@Overridepublic 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 errorif (error.getException() !=null) { error.getException().printStackTrace(); } } });} catch(AdjoeNotInitializedException e) {// make sure to initialize the adjoe SDK first}
try { Adjoe.doPayout(context, object: AdjoePayoutListener {overridefunonPayoutExecuted(coins: Int) {// successfully paid out 'coins' coins }overridefunonPayoutError(adjoePayoutError: AdjoePayoutError) {// an error occurred while paying out the coins// get information about why it failed// 'reason' is one of// - AdjoePayoutError.UNKNOWN// - AdjoePayoutError.NOT_ENOUGH_COINS// - AdjoePayoutError.TOS_NOT_ACCEPTEDval reason = adjoePayoutError.reason// if available, get more information about the errorif (error.exception !=null) { error.exception.printStackTrace() } } });} catch(e: AdjoeNotInizializedException) {// 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:
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:
privatestaticfinallong PAYOUT_RETRY_BASE =2000;privatestaticfinallong PAYOUT_RETRY_MULTIPLIER =2;privatestaticfinalint MAX_PAYOUT_RETRIES =5;privatestaticfinalHandler ADJOE_PAYOUT_HANDLER =newHandler();publicvoiddoAdjoePayout() {doAdjoePayoutInternal(0);}privatevoiddoAdjoePayoutInternal(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 properlyreturn; }Adjoe.doPayout(context,newAdjoePayoutListener() { @OverridepublicvoidonPayoutExecuted(int coins) {// everything is fine, coins have been paid out } @OverridepublicvoidonPayoutError(AdjoePayoutError error) {if (error.getReason() ==AdjoePayoutError.NOT_ENOUGH_COINS) {ADJOE_PAYOUT_HANDLER.postDelayed(newRunnable() { @Overridepublicvoidrun() {doAdjoePayoutInternal(times +1); } }, PAYOUT_RETRY_BASE *Math.pow(PAYOUT_RETRY_MULiTIPLiER, times)); } } });}
privateval PAYOUT_RETRY_BASE:Long=2000privateval PAYOUT_RETRY_MULTIPLIER:Long=2privateval MAX_PAYOUT_RETRIES =5privateval ADJOE_PAYOUT_HANDLER =Handler()fundoAdjoePayout() {doAdjoePayoutInternal(0)}privatefundoAdjoePayoutInternal(times:Int) {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 properlyreturn } Adjoe.doPayout(context, object:AdjoePayoutListener() {funonPayoutExecuted(coins:Int) {// everything is fine, coins have been paid out }funonPayoutError(error:AdjoePayoutError) {if (error.getReason() === AdjoePayoutError.NOT_ENOUGH_COINS) { ADJOE_PAYOUT_HANDLER.postDelayed(object:Runnable {publicoverridefunrun() {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,newAdjoeRewardListener() { @OverridepublicvoidonUserReceivesReward(AdjoeRewardResponse adjoeRewardResponse) {// successfully requested the rewards// get how many rewards the user has collectedint reward =adjoeRewardResponse.getReward();// get how many rewards are available for payoutint availableForPayout =adjoeRewardResponse.getAvailablePayoutCoins();// get how many rewards the user has already spentint alreadySpentCoins =adjoeRewardResponse.getAlreadySpentCoins(); } @OverridepublicvoidonUserReceivesRewardError(AdjoeRewardResponseError adjoeRewardResponseError) {// an error occurred while requesting the rewards// you can try to get additional information about the error for debuggingif (adjoeRewardResponseError.getException() !=null) {adjoeRewardResponseError.getException().printStackTrace(); } } });} catch (AdjoeNotInitializedException e) {// make sure to initialize the adjoe SDK first}
privateval PAYOUT_RETRY_BASE:Long=2000privateval PAYOUT_RETRY_MULTIPLIER:Long=2privateval MAX_PAYOUT_RETRIES =5privateval ADJOE_PAYOUT_HANDLER =Handler()fundoAdjoePayout() {doAdjoePayoutInternal(0)}privatefundoAdjoePayoutInternal(times:Int) {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 properlyreturn } Adjoe.doPayout(context, object:AdjoePayoutListener() {funonPayoutExecuted(coins:Int) {// everything is fine, coins have been paid out }funonPayoutError(error:AdjoePayoutError) {if (error.getReason() === AdjoePayoutError.NOT_ENOUGH_COINS) { ADJOE_PAYOUT_HANDLER.postDelayed(object:Runnable {publicoverridefunrun() {doAdjoePayoutInternal(times +1) } }, PAYOUT_RETRY_BASE * Math.pow(PAYOUT_RETRY_MULiTIPLiER, times)) } } })}
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: