Native
Overview
Loading native ads consists of several stages:
- Loading BidMachine NativeRequest
- Setting up AdMob AdRequest by loaded BidMachine NativeRequest
- Loading native ad through AdMob AdLoader with configured AdMob AdRequest
Loading BidMachine NativeRequest
Create a new NativeRequest instance with AdRequestListener.
Execute request
on the NativeRequest instance to start loading.
When the onRequestSuccess
callback is triggered, it means that the request has been successfully loaded and you can proceed to AdMob AdRequest settings.
// Create new BidMachine NativeRequest instance
NativeRequest nativeRequest = new NativeRequest.Builder()
.setListener(new NativeRequest.AdRequestListener() {
@Override
public void onRequestSuccess(@NonNull NativeRequest nativeRequest,
@NonNull AuctionResult auctionResult) {
runOnUiThread(() -> loadAdMobNative(nativeRequest));
}
})
.build();
// Request an ad from BidMachine without loading it
nativeRequest.request(...);
Setting up AdMob AdRequest
Ways to set up AdMob AdRequest by BidMachine NativeRequest:
- Create a new AdMob AdRequest instance
AdRequest adRequest = BidMachineUtils.createAdRequest(nativeRequest);
- Create a new AdMob AdRequest.Builder instance
AdRequest.Builder adRequestBuilder =
BidMachineUtils.createAdRequestBuilder(nativeRequest);
AdRequest adRequest = adRequestBuilder.build();
- Fill an existing AdMob AdRequest.Builder instance
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
BidMachineUtils.appendRequest(adRequestBuilder, nativeRequest);
AdRequest adRequest = adRequestBuilder.build();
Loading native ad through AdMob AdLoader
Use the AdMob AdRequest that was created during the previous step to load native ad through AdMob AdLoader.
// Create new AdLoader instance
AdLoader adLoader = new AdLoader.Builder(..., ...)
.forNativeAd(...)
.withAdListener(...)
.build();
// Load native ad with AdMob AdRequest
adLoader.loadAd(adRequest);
Sample App
You can find Sample App with BidMachineSDK and AdMob here: Github Native
Updated about 2 months ago
What’s Next