Rewarded Ads for Native Android

This section explains the steps to integrate the now.gg Rewarded Ads module with your development environment.

To get started, download the now.gg SDK download package that contains the Rewarded Ads module and add them to your development environment.

Note: The now.gg SDK download package contains the Rewarded Ads module, demo app, and code.

Add SDK Libraries

1. Extract the compressed now.gg Rewarded Ads module and locate the .aar file in the package:

   
 RewardedAds.aar

2. Add the following dependency to the build.gradle file of your game:

   
 dependencies {
         implementation fileTree(dir: 'libs', include: ['*.aar'])
 }

Initialize the Rewarded Ads Module

Before your app can show the ads, you must initialize the module from the onCreate method of your app’s main activity.

To initialize the module, call the NowGGAds.initialize() function. Once the initialisation is complete, the function will also generate a callback on the completion listener.

Note: You should initialize the module only once, ideally at app launch.

The following code segment illustrates this implementation:

public class MainActivity extends AppCompatActivity {
 public static final String TAG = "RewardsTest";
 public Button showAdButton;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     showAdButton = findViewById(R.id.showAd);

     NowGGAds.initialize(this, new OnInitializationCompleteListener() {
         @Override
         public void onInitializationComplete(InitializationStatus initializationStatus) {
             Log.d(TAG, "onInitializationComplete: " + initializationStatus);

             if (initializationStatus.getState().equals(State.NOT_READY)) {
                 Log.d(TAG, "onInitializationComplete: error");
                 // retry creating NowGGAds
             }
         }
     });
 }
 }

Show Rewarded Ads

Once the module has been successfully initialized, you can now show the in-app rewarded ads.

Based on your requirements, you can display the rewarded ads in your app by calling the NowGGAds.showRewardedAd() function of the Rewarded Ads module.

now.gg Rewarded Ads utilizes the following callback functions to inform your app about the status of the rewarded ad request:

  • void onAdShownToUser(); – Ad is displayed on the user’s screen.
  • void onAdFailedToLoad(String reason); – Ad failed to load.
  • void onAdDismissed(boolean rewardEarned); – Ad was dismissed by the user. Continue with app operations.
    • If the Ad was prematurely dismissed by the user, rewardEarned will be False.
    • If the Ad completes its required run time to earn the reward, rewardEarned will be True.
  • void onUserEarnedReward(); – User earned a reward.

The following code segment illustrates the above-listed callback functions and their implementation:

 
showAdButton.setOnClickListener(view -> {
    NowGGAds.showRewardedAd(this, new AdStatusListener() {
       
 // Ad is displayed on the User's screen
        @Override
        public void onAdShownToUser() {
            Toast.makeText(getBaseContext(), "Ad is displayed on the user’s screen", Toast.LENGTH_LONG).show();
        }
      
 // Ad failed to load
        @Override
        public void onAdFailedToLoad(String s) {
            Log.d(TAG, "onAdFailedToLoad() called with: s = [" + s + "]");
            Toast.makeText(getBaseContext(), "Ad failed to load", Toast.LENGTH_SHORT).show();
        }

 //Ad was dismissed by the user; continue with app operations.
        @Override
        public void onAdDismissed(boolean rewardEarned) {
            if (rewardEarned)
                Toast.makeText(getBaseContext(), "Congrats, you earned a reward", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(getBaseContext(), "Ad was dismissed - No reward this time!", Toast.LENGTH_LONG).show();
        }

 //User earned a reward
        @Override
        public void onUserEarnedReward() {
            Log.d(TAG, "rewardEarned");
        }
    });
 });

Important Information

×

Document Rev. 1.0

Text copied to clipboard
Link copied to clipbord
Questions? Please reach out to us at dev-support@now.gg