Skip to content

Instantly share code, notes, and snippets.

@melty710
Last active September 25, 2015 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melty710/6cf7b491d2b6d49dac9a to your computer and use it in GitHub Desktop.
Save melty710/6cf7b491d2b6d49dac9a to your computer and use it in GitHub Desktop.
Android Tapjoy Rewarded Video
// Sample initialization code for setting up earned currency notifications when using Tapjoy-managed currency
protected void onCreate(Bundle savedInstanceState) {
...
Tapjoy.connect(getApplicationContext(), tapjoySDKKey, connectFlags, new TJConnectListener() {
@Override
public void onConnectSuccess() {
// If using Tapjoy managed currency, add a listener to be notified when a user has successfully earned currency.
// http://dev.tapjoy.com/virtual-currency/managed-currency/
Tapjoy.setEarnedCurrencyListener(new TJEarnedCurrencyListener() {
@Override
public void onEarnedCurrency(String currencyName, int amount) {
Log.i("Tapjoy", "You've just earned " + amount + " " + currencyName);
}
});
// Best Practice: If using Tapjoy's managed currency service, we recommend calling getCurrencyBalance as often as possible
// so the user’s balance is always up-to-date.
Tapjoy.getCurrencyBalance(new TJGetCurrencyBalanceListener() {
@Override
public void onGetCurrencyBalanceResponse(String currencyName, int balance) {
// Update the currency balance in the UI
}
@Override
public void onGetCurrencyBalanceResponseFailure(String error) {}
});
}
...
});
}
// Sample Rewarded Video callback code for managing rewards
public void onRewardedVideoClosed(@NonNull String adUnitId) {
// Best Practice: If using Tapjoy's managed currency service, we recommend calling getCurrencyBalance as often as possible
// so the user’s balance is always up-to-date.
Tapjoy.getCurrencyBalance(new TJGetCurrencyBalanceListener() {
@Override
public void onGetCurrencyBalanceResponse(String currencyName, int balance) {
// Update the currency balance in the UI
}
@Override
public void onGetCurrencyBalanceResponseFailure(String error) {}
});
}
public void onRewardedVideoCompleted(@NonNull Set<String> adUnitIds, @NonNull MoPubReward reward) {
if(reward.getAmount() != MoPubReward.NO_REWARD_AMOUNT) {
// If using Tapjoy's managed currency service, tell Tapjoy to award the user the reward amount specified by MoPub
// http://dev.tapjoy.com/virtual-currency/managed-currency/
Tapjoy.awardCurrency(reward.getAmount(), new TJAwardCurrencyListener() {
@Override
public void onAwardCurrencyResponseFailure(String error) {}
@Override
public void onAwardCurrencyResponse(String currencyName, int balance) {}
});
// If using a different currency managing system, tell that system to award the user the reward amount specified by MoPub
// For Tapjoy rewards, you should have received a postback directly to your currency server using the callbackUrl specified on your Tapjoy currency
// http://dev.tapjoy.com/virtual-currency/non-managed-currency/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment