The Audience Bidding Android SDK integration guide (available here) will help you with the following:
Once you have added the SDK successfully, please follow the steps below to load the following ad units using Audience Bidding.
To add a banner ad in Android code, create an instance of InMobiBanner:
InMobiBanner bannerAd = new InMobiBanner(BannerAdsActivity.this, <placementid>);
InMobiBanner
class is not thread-safe. A banner instance must be created on the UI thread.To set the banner size in Android code, write the following code:
bannerAd.setBannerSize(<widthindp>, <heightindp>);
Requesting for a bid requires you to set the size of the Banner ad before requesting for a bid on the InMobiBanner
instance. Once you have set the size of InMobiBanner
ad, you can call the InMobiBanner#getPreloadManager()#preload()
method on the instance you just created to request for a bid.
/** * A sample code to request bid */
public class YourActivity {
private InMobiBanner banner;
public void requestBid() {
banner.setListener(new BannerAdEventListener() {
/** * Called to notify that an ad was successfully loaded.
* @param ad Represents the {@link InMobiBanner} ad which was loaded
* @param info Represents the ad meta information
*/
@Override
public void onAdFetchSuccessful(@NonNull InMobiBanner ad, @NonNull
AdMetaInfo info) {
double bid = info.getBid(); Log.d(TAG, "Bid received : " + bid);
}
/**
* Called to notify that an ad preload has failed.
Note: This* notification is given only when you use {@code preload()} in
* {@link InMobiBanner#getPreloadManager()}
*
* @param ad Represents the ad which was preloaded
* @param status Represents the {@link InMobiAdRequestStatus} status
containing error reason
*/
@Override
public void onAdFetchFailed(@NonNull InMobiBanner ad, @NonNull
InMobiAdRequestStatus status) {
Log.d(TAG, "Bid fetch failure : " + status.getMessage());
}
});
// Step to preload banner
banner.getPreloadManager().preload();
}
}
You’ve to maintain this banner instance for loading the ad later, in case InMobi won the auction.
In case InMobi has won the auction, then you can call the InMobiBanner#getPreloadManager()#load()
method on the instance to load the ad.
/**
* A sample code to load ad
*/
public class InMobiCustomEvent {
private InMobiBanner banner;
/**
* A sample load method for your PPM
*/
@Override
protected void loadBanner() {
// Custom event load, publisher to hold InMobiBanner object
this.banner.setListener(new BannerAdEventListener() {
/**
* Called to notify that an ad was successfully loaded and is ready to be displayed.
*
* @param ad Represents the ad which was loaded
* @param info Represents the ad meta information
*/
@Override
public void onAdLoadSucceeded(@NonNull InMobiBanner ad, @NonNull AdMetaInfo info) {
Log.d(TAG, "Banner displayed");
}
/**
* Called to notify that a request to load an ad failed.
*
* @param ad Represents the ad which failed to load
* @param status Represents the {@link InMobiAdRequestStatus} status containing error reason
*/
@Override
public void onAdLoadFailed(@NonNull InMobiBanner ad, InMobiAdRequestStatus status) {
Log.d(TAG, "Banner display failed");
}
});
this.banner.getPreloadManager().load();
}
// Other code
}
To create an interstitial ad, create an instance of an InMobiInterstitial like so:
InMobiInterstitial interstitialAd = new InMobiInterstitial(InterstitialAdsActivity.this, <placementid>,
mInterstitialAdEventListener);
Requesting for a bid requires you to call the API InMobiInterstitial#getPreloadManager()#preload()
method on the instance you just created to request for a bid.
/**
* A sample code to request bid
*/
public class YourActivity {
private InMobiInterstitial interstitial;
public void requestBid() {
interstitial = new InMobiInterstitial(context, <placementid>, new
InterstitialAdEventListener() {
/**
* Called to notify that an ad was successfully loaded.
* @param ad Represents the {@link InMobiInterstitial} ad which was loaded
* @param info Represents the ad meta information
*/
@Override
public void onAdFetchSuccessful(@NonNull InMobiInterstitial ad, @NonNull
AdMetaInfo info) {
double bid = info.getBid(); Log.d(TAG, "Bid received : " + bid);
}
/**
* Called to notify that an ad preload has failed.
Note: This * notification is given only when you use
{@code preload()} in
* {@link InMobiInterstitial#getPreloadManager()}
*
* @param ad Represents the ad which was preloaded
* @param status Represents the {@link InMobiAdRequestStatus} status
containing error reason
*/
@Override
public void onAdFetchFailed(@NonNull InMobiInterstitial ad, @NonNull
InMobiAdRequestStatus status) {
Log.d(TAG, "Bid fetch failure : " + status.getMessage());
}
});
// Step to preload interstitial
interstitial.getPreloadManager().preload();
}
}
You’ve to maintain this interstitial instance for loading the ad later, in case InMobi won the auction.
In case InMobi has won the auction, then you can call the InMobiInterstitial#getPreloadManager()#load()
method on the instance to load the ad followed by InMobiInterstitial#show()
to show the ad.
/**
* A sample code to load ad
*/
public class InMobiCustomEvent {
private InMobiInterstitial interstitial;
/**
* A sample load method for your PPM
*/
@Override
protected void loadInterstitial() {
// Custom event load, publisher to hold InMobiInterstitial object
interstitial.setListener(new InterstitialAdEventListener() {
/**
* Called to notify that an ad was successfully loaded and is ready to be displayed.
*
* @param ad Represents the ad which was loaded
* @param info Represents the ad meta information
*/
@Override
public void onAdLoadSucceeded(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {
Log.d(TAG, "Interstitial loaded");
}
/**
* Called to notify that a request to load an ad failed.
*
* @param ad Represents the ad which failed to load
* @param status Represents the {@link InMobiAdRequestStatus} status containing error reason
*/
@Override
public void onAdLoadFailed(@NonNull InMobiInterstitial ad, @NonNull InMobiAdRequestStatus status) {
Log.d(TAG, "Interstitial load failed");
}
});
this.interstitial.getPreloadManager().load();
}
/**
* A sample show method for your PPM
*/
@Override
protected void showInterstitial() {
if (this.interstitial.isReady()) {
this.interstitial.show();
}
}
// Other code
}
By installing this SDK update, you agree that your Children Privacy Compliance setting remains accurate or that you will update that setting, whenever there is a change in your app's audience. You may update the app's Children Privacy Compliance settings at https://publisher.inmobi.com/my-inventory/app-and-placements.