This page will show you how to integrate Leadbolt Video and Interstitial ads in your Android app with B4A. Download the SDK and sample app. Make sure you can compile the sample app and see test ads.
- Before you begin
- Add Leadbolt SDK files
- Add the required Permissions and Activity in your B4A Manifest Editor
- Add Leadbolt SDK Imports
- Initialize Leadbolt SDK
- To Cache and Show a non-Rewarded Ad
- To Cache and Show a Rewarded Ad
- Test your Integration
- Advanced Integration
- Checking Ad Availability
- Passing Additional Information
- Using Event Listeners
Before you begin
- Have you signed up and logged in to the Leadbolt Publisher Portal?
- Did you add an App in the portal?
- Ensure, you have downloaded the Leadbolt SDK and sample app from the link above
Add Leadbolt SDK files
- Copy the four downloaded files ( AppTracker.jar, AppTracker.xml, AppTrackerB4A.jar and AppTrackerB4A.xml) to the folder which the B4A IDE references for “Additional Libraries”.
Add the required Permissions and Activity in your B4A Manifest Editor
- Add the required permission android.permission.INTERNET in the Manifest Editor
- Add the required permission android.permission.ACCESS_NETWORK_STATE in the Manifest Editor
- Add the required Leadbolt Activity in the Manifest Editor
XHTML123456<activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize"android:name="com.apptracker.android.module.AppModuleActivity"android:hardwareAccelerated="false"android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"></activity><service android:name="com.apptracker.android.track.AppTrackerService" />
Add Leadbolt SDK Imports
- Add the following Leadbolt SDK import statement your Globals Sub.
Visual Basic .NET12345Sub GlobalsDim AppTracker As AppTrackerB4AEnd Sub
Initialize Leadbolt SDK
- In your App’s code, add the following code to your
Visual Basic .NET123567Sub Activity_Create(FirstTime As Boolean)' Initialize Leadbolt SDK with your API KeyAppTracker.startSession(True)End Sub
You will need to replace "YOUR_APP_API_KEY" with the specific api key for your app (include the double quotes).
To Cache and Show a non-Rewarded Ad
- To cache a non-Rewarded Ad
- To show a non-Rewarded Ad
- Please ensure that in your code, you do not call loadModule directly after loadModuleToCache. It will cause the SDK to fail and not display an Ad all together.
- For Advanced SDK options, including use of Event Listeners, click here.
To Cache and Show a Rewarded Ad
- To cache a Rewarded Ad
- To show a Rewarded Ad
- Please ensure that in your code, you do not call loadModule directly after loadModuleToCache. It will cause SDK to fail and not display the Rewarded Ad at all.
- To reward user, refer to the Advanced Integration on more information about Event Listeners and Rewarding Users
Test your Integration
- Run your Project on an Android device.
- Ensure, test ads are displayed when the “loadModule” call is made in your App.
- Once test ads are seen on your device, go to your Leadbolt Portal and set your App to “Live”
- Once approved, you should see live ads in your App.
Congratulations! You have successfully integrated the Leadbolt SDK in your App
- Video and Interstitial Ads may not be available at all times in all countries. It is always best to test with your App in Test Mode in the Publisher Portal to ensure as Test Ads are generally always available.
- You should check your Publisher Portal and ensure the relevant section is visible under your App. Use the “Add Section” button to add if not available.
- You should check the SDK logs located in Logcat logs with the Tag “AppTracker”.
- Always test the sample app provided to confirm any integration issues are SDK based.
- This plugin has been tested on the following versions of B4A: 6.50
Checking Ad Availability
Leadbolt SDK provides additional ability to the developers to check before hand if an Ad is available before displaying it to create a better user-experience in your App. To check if a Network or Direct Deal Ad is available please use the code below:
If (AppTracker.isAdReady("inapp")) Then
' Ad is available to be displayed
' Ad not ready to be displayed yet
To check if a Rewarded Ad is available to be displayed, please use the code below:
If (AppTracker.isAdReady("reward")) Then
' Rewarded Ad is available to be displayed
' Rewarded Ad not ready to be displayed yet
Passing Additional Information
You can increase your App’s performance by optionally including the additional information below. This allows selected premium advertisers to display their Ads to your users. To pass this additional information, use the following methods BEFORE calling loadModuleToCache
' Allowed values for Age range are: "13-17", "18-25", "26-35", "36-45", "46+"
' Allowed values for Gender are: "Male", "Female"
Using Event Listeners
With Event listeners, you can closely follow the ad states throughout your App. Leadbolt SDK will trigger events at all important stages of the Ad life-cycle. To implement event listeners in your App, add the following subs to your B4A project
Sub apptracker_onmodulecached(Placement As String)
' Ad cached successfully
' Add code if not auto-recaching for when loadModuleModuleToCache is successful
Sub apptracker_onmoduleloaded(Placement As String)
' Ad loaded successfully
' Add code here to pause game and/or all media including audio
Sub apptracker_onmoduleclosed(Placement As String, Reward As Boolean)
' Ad closed by user
' Add code here to resume game and/or all media including audio
If (Reward) Then
' Reward Triggered
Sub apptracker_onmodulefailed(Placement As String, Error As String, IsCached As Boolean)
If (IsCached) Then
' Ad failed to cache
' Ad failed to load
Sub apptracker_onmoduleclicked(Placement As String)
' Ad clicked by user