Android Rewarded Video Ads

This section describes how to integrate with the AdFalcon’s Android SDK in order to consume the services available by the network.

Integration Steps

We recommend you to load the rewarded video ad in the Application class of your App. that will help you to pre-load the Ad and show the ad when you need.

in order to integrate with the SDK, please perform the following steps:

Implement ADFRewardedVideoAdListener (Optional but recommended)

To know if the user deserves the rewarded items or not, you have to implement the ADFRewardedVideoAdListener to listen to onRewarded listener’s method; this methods will inform the developer when the user becomes deserving of the rewarded item.

To implement the ADFRewardedVideoAdListener, you should import the classes and the listener of ADFRewardedVideoAd then implement the listener to your class as the code snippet below

import com.noqoush.adfalcon.android.sdk.constant.ADFErrorCode;
import com.noqoush.adfalcon.android.sdk.video.reward.ADFRewardedVideoAd;
import com.noqoush.adfalcon.android.sdk.video.reward.ADFRewardedVideoAdListener;

public class AdFalconRewardedVideoAdHelper implements ADFRewardedVideoAdListener{

    public static final String SITE_ID = "Set your site id here";
    private ADFRewardedVideoAd mRewardedVideoAd;

    /*
     * This Method is fired when the rewarded video ad is loaded completely
     */
    @Override
    public void onRewardedVideoAdLoaded(ADFRewardedVideoAd adfRewardedVideoAd) {

    }


    /*
     * This Method is fired when the video ad has started displaying
     */
    @Override
    public void onRewardedVideoAdOpened() {

    }

    /*
     * This Method is fired when the video ad has started playing
     */
    @Override
    public void onRewardedVideoStarted() {

    }


    /*
     * This Method is fired when the user clicks on an action (link or button) in the ad. The action will perform in an outside-app such as "App Install Action".
     */
    @Override
    public void onRewardedVideoAdLeftApplication() {

    }

    /*
     * This Method is fired when there is no available ad, no Internet connection or any unexpected exception or error occurred during the loading of the ad
     */
    @Override
    public void onRewardedVideoAdFailedToLoad(ADFErrorCode adfErrorCode, String s) {

    }


    /*
     * This Method is fired when the player failed to play the video's content. (e.g. the video format is not supported by the Android OS).
     */
    @Override
    public void onRewardedVideoAdFailedToOpen(ADFErrorCode adfErrorCode, String s) {

    }


    /*
     * This Method is fired when the user becomes deserving of the rewarded item
     */
    @Override
    public void onRewarded(String s, int i) {

    }


    /*
     * This Method is fired when the video ad reached to the end of the content, in other words the video was shown completely
     */
    @Override
    public void onRewardedVideoEnded() {

    }


    /*
     * This Method is fired when the user clicked on the close button after watching the ad.
     */
    @Override
    public void onRewardedVideoAdClosed() {

    }


Create and load Rewaded video Ad

Create a new instance of ADFRewardedVideoAd, then set the listener to the instance. After that request a new ad by calling requestAd with your Site Id and ADFTargetingParams from the instance of the ADFRewardedVideoAd.

Note: Before creating a new instance of the rewarded video ad, we recommend checking if there is a ready instance or not.


    /*
     * This method will check if there is an ad ready or not.
     */
    public boolean isReady(){
        return mRewardedVideoAd != null && mRewardedVideoAd.isReady();
    }

    /*
     * This method will check if there is an ad ready,
     * if not, it will create a new instance of ADFRewardedVideoAd and set the listener to the instance, after that it will request a new ad.
     */
    public void loadRewardedVideo(Context context){

        if(!isReady()){
            mRewardedVideoAd = new ADFRewardedVideoAd(context);
            mRewardedVideoAd.setListener(this);
            mRewardedVideoAd.requestAd(SITE_ID, null);
        }
    }

Show the Ad

To show the rewarded video ad, you only need to call show method with the top active activity from the instance of the ADFRewardedVideoAd.

Note: We recommend checking if the ADFRewardedVideoAd is not null and ready to be shown, before calling the “show” method.

    /*
     * This method will check if there is an ad ready, and present the rewarded video ad from the passed activity
     */
    public void showAd(Activity activity){
        if(isReady()) {
            mRewardedVideoAd.show(activity);
        }else{
            Log.w("AdFalconSDK", "No Ad available to be shown");
        }
    }

Full Example

    

import android.app.Activity;
import android.content.Context;
import android.util.Log;


import com.noqoush.adfalcon.android.sdk.constant.ADFErrorCode;
import com.noqoush.adfalcon.android.sdk.video.reward.ADFRewardedVideoAd;
import com.noqoush.adfalcon.android.sdk.video.reward.ADFRewardedVideoAdListener;

public class AdFalconRewardedVideoAdHelper implements ADFRewardedVideoAdListener{

    public static final String SITE_ID = "Set your site id here";
    private ADFRewardedVideoAd mRewardedVideoAd;

    /*
     * This method will check if there is an ad ready,
     * if not, it will create a new instance of ADFRewardedVideoAd and set the listener to the instance, after that it will request a new ad.
     */
    public void loadRewardedVideo(Context context){

        if(!isReady()){
            mRewardedVideoAd = new ADFRewardedVideoAd(context);
            mRewardedVideoAd.setListener(this);
            mRewardedVideoAd.requestAd(SITE_ID, null);
        }
    }


    /*
     * This method will check if there is an ad ready or not.
     */
    public boolean isReady(){
        return mRewardedVideoAd != null && mRewardedVideoAd.isReady();
    }

    /*
     * This method will check if there is an ad ready, and present the rewarded video ad from the passed activity
     */
    public void showAd(Activity activity){
        if(isReady()) {
            mRewardedVideoAd.show(activity);
        }else{
            Log.w("AdFalconSDK", "No Ad available to be shown");
        }
    }


    /*
     * This Method is fired when the rewarded video ad is loaded completely
     */
    @Override
    public void onRewardedVideoAdLoaded(ADFRewardedVideoAd adfRewardedVideoAd) {

    }


    /*
     * This Method is fired when the video ad has started displaying
     */
    @Override
    public void onRewardedVideoAdOpened() {

    }

    /*
     * This Method is fired when the video ad has started playing
     */
    @Override
    public void onRewardedVideoStarted() {

    }


    /*
     * This Method is fired when the user clicks on an action (link or button) in the ad. The action will perform in an outside-app such as "App Install Action".
     */
    @Override
    public void onRewardedVideoAdLeftApplication() {

    }

    /*
     * This Method is fired when there is no available ad, no Internet connection or any unexpected exception or error occurred during the loading of the ad
     */
    @Override
    public void onRewardedVideoAdFailedToLoad(ADFErrorCode adfErrorCode, String s) {

    }


    /*
     * This Method is fired when the player failed to play the video's content. (e.g. the video format is not supported by the Android OS).
     */
    @Override
    public void onRewardedVideoAdFailedToOpen(ADFErrorCode adfErrorCode, String s) {

    }


    /*
     * This Method is fired when the user becomes deserving of the rewarded item
     */
    @Override
    public void onRewarded(String s, int i) {

    }


    /*
     * This Method is fired when the video ad reached to the end of the content, in other words the video was shown completely
     */
    @Override
    public void onRewardedVideoEnded() {

    }


    /*
     * This Method is fired when the user clicked on the close button after watching the ad.
     */
    @Override
    public void onRewardedVideoAdClosed() {

    }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s