Rewarded Video Ads Integration for Android

Do go through the steps in our Getting Started Guide to add Media.Net SDK into your project before starting the integration of Rewarded Video Ads.

For adding rewarded video ads to your app, following are the steps:

  • Add the video dependency to your build.gradle file
  • Load a rewarded video ad
  • Set up listeners

    a. Add Video dependency to your build.gradle file

    For rewarded video ads, it is required to add an additional dependency to your build.gradle file. The below-mentioned dependencies need to be added to your build.gradle.

          dependencies  {
            compile "net.media.android:base:1.2.5"
            compile "net.media.android:video:1.2.5"
          }
    

    b. Add these lines to load rewarded video ad

    Create an instance of RewardedVideo class in your activity.

          RewardedVideo rewardedVideo = new RewardedVideo(this, "XXXXXXXXX") //Enter ad unit id
    

    Load rewarded video ad.

          rewardedVideo.load();
    

    c. Listen to rewarded video ad state

          rewardedVideo.addRewardedVideoListener(new RewardedVideoListener() {
    
               // Sent when the rewarded video ad is started.
               @Override public void onRewardedVideoStarted() {
                     //Do your stuff   
               }          
    
               // Sent when rewarded video ad is completed.
               @Override public void onRewardedVideoCompleted(MNetReward reward) {
                    //Do your stuff            
               }
    
               // Sent when the ad slot has failed to retrieve an ad.
               @Override public void onError(final MNetError error) {
                    //Do your stuff
               }
    
               // Sent when the rewarded video playback error occurs.
               @Override public void onRewardedVideoPlaybackError(String error, int errorCode) {
                    //Do your stuff             
               }
    
               // Sent when the rewarded video ad is shown.
               @Override public void onRewardedVideoShown() {
                    //Do your stuff     
               }
    
               // Sent when the rewarded video ad is clicked.
               @Override public void onRewardedVideoClicked() {
                    //Do your stuff     
               }
    
               // Sent when the rewarded video ad is loaded.
               @Override public void onRewardedVideoLoaded() {
                    //Do your stuff     
               }
          });