Android SDK – Ads

Step 1: Enable ads

Make a call to HeyzapAds.start(this) as early in your game’s initialization code as you can, preferably directly after your call to HeyzapLib.load(). That will give our SDK time to prefetch the ads, and ensure your users never see a loading spinner.
import com.heyzap.sdk.ads.HeyzapAds;

HeyzapLib.load(this, false);
HeyzapAds.start(this);

Step 2: Edit your game’s AndroidManifest.xml

For the ads sdk, we require the INTERNET and ACCESS_NETWORK_STATE permission. This lets us know if the user is connected to the internet, as we only want to show ads to users who can download games.
To add these permissions to your manifest file, add the following lines anywhere between the <manifest> and </manifest> tags in your AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
In addition, we have a BroadcastReceiver that lets us know when users install a game so we can credit your account with the install.
To enable the broadcast receiver, add the following lines anywhere between the <application> and </application> tags in your AndroiManifest.xml.
<receiver android:name="com.heyzap.sdk.PackageAddedReceiver">
<intent-filter>
<data android:scheme="package"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
</intent-filter>
</receiver>

Step 3: Show an ad Interstitials

Whenever you want to show an interstitial ad, call:
import com.heyzap.sdk.ads.InterstitialOverlay;

InterstitialOverlay.display(this);
where this is an Activity class (important!)
If you wish to hide the ad, call
InterstitialOverlay.dismiss();
If an in-game ad is available or loading, this call will show a loading dialog or an ad dialog. If no ad is available, nothing will be displayed. In either case this call will return immediately, allowing you to conduct other work in the background (such as loading the next level).
We recommend this call be made after a player completes a level or where there is a natural break in play.

Testing

The game displaying the ads must be in Heyzap’s databases or the ad will not work.
To ensure your game is in the Heyzap database, search by Android package name on the Developer Dashboard. (TIP: You can claim your games to see stats on your integration.) If your game does not appear, you need to manually add it to the Heyzap database here before testing.

Post By: Nishant Anindya