Skip to content

Rewarded Video Integration

Farzad Seid Arabi edited this page Jan 30, 2017 · 4 revisions

#Rewarded Video for Android

##Overview Rewarded video ads are a great way to offer users an incentive to stay engaged in your app, while earning more ad revenue. The reward generally comes in the form of in-game currency (gold, coins, power-ups) and is distributed to the user after a successful video completion.

##Basic Integration ####1. Include the custom event class and JAR for the mediated networks.

All the CustomEventRewardedVideo subclasses are included in the extras/com/sabavision/mobileads/ directory:

  • AdColony: AdColonyRewardedVideo.java
  • Chartboost: ChartboostRewardedVideo.java
  • Vungle: VungleRewardedVideo.java
  • Unity Ads: UnityRewardedVideo.java
  • Tapjoy: TapjoyRewardedVideo.java

For each mediated network that you would like to support, copy the corresponding source file into your application’s com.sabavision.mobileads package, and copy the corresponding mediated network SDKs into your application’s libs/ directory.

Initialize Sabavision rewarded video in your Activity’s onCreate().

You do not need to explicitly initialize any mediated rewarded video networks — the Sabavision SDK properly handles that logic.

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SabaVision.initializeRewardedVideo(this);
        // ...
    }
 }

Cache rewarded videos for a given adUnitId (often a placement within the app, e.g. game over screen or in-app store). For example:

private void loadRewardedVideo(){    
	SabaVision.loadRewardedVideo("YOUR_AD_UNIT_ID");   
}

Check if rewarded videos are available using SabaVision.hasRewardedVideo(String adUnitId) before offering to display them to the user.

Show the rewarded video when the user clicks to watch it. For example:

private void userClickedToWatchAd() {    
	SabaVision.showRewardedVideo("YOUR_AD_UNIT_ID");   
}

####2. Integrate lifecycle callbacks

Network SDKs need to be notified of changes in the activity lifecycle so they can keep track of the current activity and load/show rewarded videos. For example, you can add lifecycle callbacks to all of your activities (including your Launcher Activity) that will load or show rewarded videos.

Important note for specific networks:

  • For AdColony and Vungle rewarded videos, the only required lifecycle callbacks are onCreate, onPause, and onResume.
  • Chartboost rewarded videos require the full set below.
  • For additional help on Tapjoy integration, check here
  • Unity only requires onCreate and onResume. (see Integrate With the Activity Lifecycle")
public class MainActivity extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SabaVision.initializeRewardedVideo(this);
		SabaVision.onCreate(this);
		// ...
	}
    
    @Override
    public void onPause() {
        super.onPause():
        SabaVision.onPause(this);
    }
 
    @Override
    public void onResume() {
        super.onResume():
        SabaVision.onResume(this);
    }
 
    // The following methods are required for Chartboost rewarded video mediation
    @Override
    public void onStart() {
        super.onStart():
        SabaVision.onStart(this);
    }
 
    @Override
    public void onRestart() {
        super.onRestart():
        SabaVision.onRestart(this);
    }
 
    @Override
    public void onStop() {
        super.onStop():
        SabaVision.onStop(this);
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy():
        SabaVision.onDestroy(this);
    }
 
    @Override
    public void onBackPressed() {
        super.onBackPressed():
        SabaVision.onBackPressed(this);
    }
}
Optional: Set a rewarded video listener

You can set a rewarded video listener to receive relevant callbacks.

public class MainActivity extends Activity {
	private SabaVisionRewardVideoListener rewardedVideoListener;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SabaVision.initializeRewardedVideo(this);
        SabaVision.onCreate(this);
 
        rewardedVideoListener = new SabaVisionRewardedVideoListener() {
            @Override
            public void onRewardedVideoLoadSuccess(String adUnitId) {
                // Called when the video for the given adUnitId has loaded. At this point you should be able to call SabaVision.showRewardedVideo(String) to show the video.
            }
            @Override
            public void onRewardedVideoLoadFailure(String adUnitId, SabaVisionErrorCode errorCode) {
                // Called when a video fails to load for the given adUnitId. The provided error code will provide more insight into the reason for the failure to load.
            }
 
            @Override
            public void onRewardedVideoStarted(String adUnitId) {
                // Called when a rewarded video starts playing.
            }
 
            @Override
            public void onRewardedVideoPlaybackError(String adUnitId, SabaVisionErrorCode errorCode) {
                //  Called when there is an error during video playback.
            }
 
            @Override
            public void onRewardedVideoClosed(String adUnitId) {
                // Called when a rewarded video is closed. At this point your application should resume.
            }
 
            @Override
            public void onRewardedVideoCompleted(Set<String> adUnitIds, SabaVisionReward reward) {
                // Called when a rewarded video is completed and the user should be rewarded.
                // You can query the reward object with boolean isSuccessful(), String getLabel(), and int getAmount().
            }
        };
 
        SabaVision.setRewardedVideoListener(rewardedVideoListener);
    }
}

###Advanced: Mediation Settings

Mediation settings enable you to pass in third-party network specific settings and can be provided as additional parameters during the rewarded video initialization call. For Vungle, Unity and Chartboost mediation, this is the only mechanism by which a user-Id or custom-Id can be specified in networks’ server-side callbacks.

Each subclass of CustomEventRewardedVideo specifies its own implementation of mediation settings with its own constructor.For example:

public class MainActivity extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SabaVision.initializeRewardedVideo(this,
 
        /* ChartboostMediationSettings */
        new ChartboostMediationSettings(“CB_CUSTOM_ID”),
 
        /* AdColonyMediationSettings */
        new AdColonyMediationSettings(true, true),
 
        /* VungleMediationSettings */
        new VungleMediationSettings.Builder()
            .withUserId(“VUNGLE_USER_ID”)
            .withCancelDialogTitle(“Cancel?”)
            .build();
        );         
        SabaVision.onCreate(this);
        // ...
    }
}