1. Home
  2. Publishers
  3. Integrating Interstitial/Rewarded Video and Interstitial Banner Ads in Android Project

Integrating Interstitial/Rewarded Video and Interstitial Banner Ads in Android Project

Step 1: Get Tapsell Key

Log in your Tapsell account and get a new tapsell key by creating a new application. This key is needed for using tapsell APIs.

 

Step 2: Import and Initialize Tapsell

Import the Tapsell library in your Application class (or launcher Activity):

import ir.tapsell.sdk.*;

Then in your onCreate method, initialize Tapsell like below:

Tapsell.initialize(context, appKey);

 

Step 3: Requesting an Ad

Showing an Ad in application may be done in two ways. Caching or Streaming the video. Moreover, you can show Ads in different zones inside your application.
To request an Ad in your application, use the following method:

Tapsell.requestAd(context, zoneId, options, new TapsellAdRequestListener() {
    @Override
    public void onError (String error)
    {
    }

    @Override
    public void onAdAvailable (TapsellAd ad)
    {
    }

    @Override
    public void onNoAdAvailable ()
    {
    }

    @Override
    public void onNoNetwork ()
    {
    }

    @Override
    public void onExpiring (TapsellAd ad)
    {
    }
});

 

In this function, zoneId argument shows the zone in which you with to show the ad. In order to use the default zone created by Tapsell, you can pass a null value for this argument.
The second argument, options is a variable of TapsellAdRequestOptions class. This object has a field variable named cacheType which indicates whether the ad should be cached before showing or streamed. Possible values for this argument are given in Table 1.

 

Table 1 Different values for cache types of ad request options
Value Description
CACHE_TYPE_CACHED Cache video file before showing ad
CACHE_TYPE_STREAMED Stream the video

The result of the request is returned to third argument, which is a listener (Callback) of type TapsellAdRequestListener interface. The overridden functions are described in Table 2.

 

Table 2 Methods of ad request listener interface
Function Description
onError (String error) Called when an error is occurred during sending request to the server.
onAdAvailable (TapsellAd ad) Called when the ad is ready to be shown. You should store the returned id in order to show the ad later.
onNoAdAvailable () Called when no suitable ad was found.
onNoNetwork() Called when device is not connected to internet.
onExpiring(TapsellAd ad) Called when the ad is expired. Ads have an expiration time and when that time is passed, that ad becomes invalid and cannot be shown. In this case, you might consider requesting a new ad.

 

Step 4: Show the Ad

To show an ad, you can call the following function on the TapsellAd object.

ad.show(context, showOptions);

 

Note that this function may be called once for each TapsellAd object.
The showOptions argument in code above is an object of TapsellShowOptions class. The setter functions of this class are described in Table 3.

 

Table 3 Methods of TapsellShowOptions object
Function Description
setBackDisabled(boolean)
Sets whether the user can use ‘Back’ button to stop playing the video.
setImmersiveMode(boolean)
Sets whether the ad must be shown in immersive mode. (Is applied in devices running Android 4.4 KitKat and above)
setRotationMode(int)
Sets the orientation of devices when showing ad. Can have one of the following values:
ROTATION_LOCKED_PORTRAIT,
ROTATION_LOCKED_LANDSCAPE,
ROTATION_UNLOCKED,
ROTATION_LOCKED_REVERSED_PORTRAIT,
ROTATION_LOCKED_REVERSED_LANDSCAPE
setShowDialog(boolean)
Show a warning alert when user presses back button while showing rewarded vide ads.

 

Step 5: Get results

Next, create and set reward listener using setRewardListener function to be alerted when user views a rewarded video completely.

Tapsell.setRewardListener(new TapsellRewardListener() {
	@Override
	public void onAdShowFinished(TapsellAd ad, boolean completed) {
		// store user reward if ad.isRewardedAd() and completed is true
	}
});

 

You should give the in-app rewards (credit, coin, gem, etc. ) to the user when the completed argument is true and the zone in which the ad was shown is rewarded (ad.isRewardedAd() returns true).

 

Sample Project

A sample project is provided in the following repository in case more information about the SDK is needed.

 

 

 

Please let us know whether this document was helpful and what complications you faced while using Tapsell Android SDK.

 

 

Next: Advanced features in SDK

Prev: Project Setup

 

Was this article helpful?

Related Articles