Bubble Ads Integration Guide
Requirements
- Android SDK 2.3 (Version 9) and above
- Android Support Library 21.0.3 and above
Installation Steps
Step I: Adding the Tooleap Ads SDK gradle dependencies to your project
Add the following lines into your build.gradle file:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
repositories { maven { url "https://tooleap-ads.github.io/maven" } } dependencies { compile 'com.android.support:appcompat-v7:21.0.3' compile('com.tooleap.ads:tooleap-ads-core:1.0.4') } |
Also add a compile dependency for each of the ad network you wish to display ads from. For example, for Facebook Audience Network add the following dependency:
|
1 2 3 4 5 6 |
dependencies { compile 'com.android.support:appcompat-v7:21.0.3' compile('com.tooleap.ads:tooleap-ads-core:1.0.4') compile('com.tooleap.ads:tooleap-ads-facebook:1.0.4') } |
Note: If you don’t use gradle build system you can download the latest jar files directly from our github repository.
Step II: Manifest Changes
Add the following permissions to your AndroidManifest.xml file:
|
1 2 |
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
Ad Networks Mediation
Tooleap displays ads from third party ad networks. In order to display ads, you need to create an account in the appropriate ad network site.
Download the appropriate jars and add a compile dependency for each of the ad network you wish to display ads from.
Facebook Audience Network
Min API Requirement: 11
Sign-in to Audience Network and create an account if you haven’t already done so. After you created an account and verified it, create a Native Ad Placement inside your Facebook Audience Network App page.
Add the newly created Placement Id to the Tooleap Ads dashboard, and add the following dependencies to the build.gradle file:
|
1 2 3 4 5 6 7 |
dependencies { compile 'com.android.support:appcompat-v7:21.0.3' compile('com.tooleap.ads:tooleap-ads-core:1.0.4') compile('com.tooleap.ads:tooleap-ads-facebook:1.0.4') compile 'com.facebook.android:audience-network-sdk:4.+' } |
consult the Facebook Audience Network Getting Started Guide on how to create you account.
Admob
Min API Requirement: 19
Sign-in to Admob and create an account if you haven’t already done so. After you created an account and verified it, create a Native Ad Unit inside your Admob App page.
Add the newly created Ad Unit Id and app id to the Tooleap Ads dashboard, and add the following dependencies to the build.gradle file:
|
1 2 3 4 5 6 7 |
dependencies { compile 'com.android.support:appcompat-v7:21.0.3' compile('com.tooleap.ads:tooleap-ads-core:1.0.4') compile('com.tooleap.ads:tooleap-ads-admob:1.0.4') compile 'com.google.android.gms:play-services-ads:10.0.1' } |
Note: You can alternatively use Admob with firebase to display ads. In this case add the following dependencies to the build.gradle file:
|
1 2 3 4 5 6 7 |
dependencies { compile 'com.android.support:appcompat-v7:21.0.3' compile('com.tooleap.ads:tooleap-ads-core:1.0.4') compile('com.tooleap.ads:tooleap-ads-admob:1.0.4') compile 'com.google.firebase:firebase-ads:10.2.1' } |
consult the Admob Getting Started Guide on how to create you account.
Display a Bubble Image Ad
The Easy-Peasy Way
To display a Bubble Ad whenever the user open an activity, simply add to your activity’s onResume the following lines:
|
1 2 3 |
BubbleImageAd = new BubbleImageAd(this); bubbleImageAd.setAdUnitId("YOUR_AD_UNIT_ID"); bubbleImageAd.loadAndShowAd(this); |
Note: If you haven’t already done this, head to the Tooleap Ads dashboard to create an Ad Unit id.
For Those Who Like To Be In Control
You can load the Bubble Ad in advance, and then show it at the appropriate time. In this example we’ll load the ad inside the Activity’s onCreate, and then show it when someMethod is called:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
public class MyActivity extends Activity { BubbleImageAd mBubbleImageAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initialize the Bubble Ad mBubbleImageAd = new BubbleImageAd(this); mBubbleImageAd.setAdUnitId("YOUR_AD_UNIT_ID"); // Load the Bubble Ad mBubbleImageAd.loadAd(new BubbleImagedLoadedListener() { @Override public void onAdLoaded(BubbleImageAd bubbleImageAd) { // Callback for when the ad is loaded } @Override public void onAdFailedToLoad(String error) { // Callback if the ad failed to load } }); } .... private void someMethod() { // Call show ad only if the ad is loaded if (mBubbleImageAd.isAdLoaded()) { mBubbleImageAd.showAd(this); } } } |
Note: You can use any Context to initialize the ad, but you need an activity to show the ad once it’s loaded.
Bubble Image Ads – Additional API
Get Notified When the User Interacts With the Ad
You can get callbacks when the user performs certain actions with the Bubble Ad by calling setAdActionsListener:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
bubbleImageAd.setAdActionsListener(new BubbleImageAdActionsListener() { @Override public void onBubbleClicked() { // Called when the user clicks on the bubble and displays the full ad } @Override public void onCallToActionButtonClicked() { // Called when the user accepts the ad offer and clicks on the call-to-action // button } @Override public void onAdMinimized() { // Called when user closes the full ad and displays the bubble again } @Override public void onAdDismissed() { // Called when the user dismisses the ad by dragging it to the 'X' at the // bottom of the screen } }); |
Dismiss the Bubble Ad
You can manually dismiss the Bubble Ad by calling dismissAd. Note that you need to call loadAd again before you can show another ad:
|
1 |
bubbleImageAd.dismissAd(); |
Change the badge on the Bubble Ad
By default when the Bubble Ad pops out it has a badge with the number “1”. You can also set the badge to show the word “Ad” or just use an empty badge as following:
|
1 2 3 4 5 6 7 8 |
// Sets an empty badge on the Bubble Ad bubbleImageAd.setBubbleBadgeType(BubbleBadgeType.EMPTY); // Sets the text "Ad" on the Bubble Ad badge bubbleImageAd.setBubbleBadgeType(BubbleBadgeType.AD); // Sets the number "1" on the Bubble Ad badge bubbleImageAd.setBubbleBadgeType(BubbleBadgeType.NOTIFICATION); |
Note: You can only change the badge type before the Bubble Ad is shown.
Change when the user can dismiss the Bubble Ad
By default the user can dismiss the Bubble Ad only after clicking on it and viewing the full ad at least once, You can allow the user to dismiss the bubble even before viewing the full ad:
|
1 2 |
// Allow the user to dismiss the Bubble Ad immediately after it appears bubbleImageAd.setAllowDismissBeforeOpen(true); |
Note: Changing this value to “true” might severely impact your ad revenues.
Proguard Support
If you are using ProGuard, you should add the following lines to your ProGuard configuration file to exclude Tooleap from being obfuscated:
|
1 2 3 4 |
-keep class com.tooleap.** { *; } -dontwarn com.tooleap.** -dontnote com.tooleap.** |
Additional Resources
Download a sample app that shows the Bubble Ads in action using this link:
