Android AdMob Mediation Adapter supports all our ad units including the unique Interscroller ad unit.
AdMob/ display.io ad units mapping:
display.io | AdMob | ||
|
Interscroller | Banner | |
|
Outstream Video | Banner | |
|
Interstitial | Interstitial | |
|
Infeed |
Banner | |
|
Medium Rectangle | Banner | |
|
Banner | Banner | |
To set it up:
1. Add the adapter to your project
Edit your project's build.gradle file in order to declare our maven repository:
repositories {
google()
jcenter()
maven { url "http://maven.display.io/" }
}
Add the following dependencies to your app-module's build.gradle file:
implementation ‘com.brandio.ads:sdk:4.5.0’
implementation ‘com.brandio.ads:adapters-admob:4.5.2'
Follow guide to initialize DisplayIO SDK.
2. Create a Google AdMob account and register an app.
3. Use Quick start from Google to setup AdMob SDK.
4. Create a mediation group.
5. In Ad sources section switch off AdMob Network and add a custom event for each ad unit using Class Name com.brandio.ads.adapters.admob.InterstitialAdapter for Interstitial ad unit or com.brandio.ads.adapters.admob.InfeedAdapter for Infeed ad unit or com.brandio.ads.adapters.admob.InterscrollerAdapter for Interscroller ad unit or com.brandio.ads.adapters.admob.BannerAdapter for Banner ad unit or com.brandio.ads.adapters.admob.MediumRectangleAdapter for Medium Rectangle ad unit
and Parameter: <PLACEMENT_ID> where <PLACEMENT_ID> parameter taken from display.io apps page.
Note: Interscroller unit also requires position of ad in your RecyclerView custom event data:
6. Use Banner (Infeed) or Interstitial tutorials to get ads from AdMob.
7. Infeed could be added in RecyclerView by passing it as adapter’s constructor argument:
RecyclerViewAdapter( ... , @NonNull AdView adView) {
...
this.adView = adView;
}
And be shown in particular position with help of RecyclerView.ViewHolder subclass in RecyclerView.Adapter.onCreateViewHolder method:
...
static class AdHolder extends RecyclerView.ViewHolder {
AdHolder(View itemView) {
super(itemView);
}
}
...
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull final
ViewGroup parent, int viewType) {
...
return new AdHolder(adView);
}
...
9. Interscroller could be added in RecyclerView with a few steps which require some modifications of RecyclerView adapter:
- First create nested static class for ad holder inside your adapter with field to store reference to parent (RecyclerView object):
static class AdHolder extends RecyclerView.ViewHolder {
public ViewGroup parent;
AdHolder(View itemView) {
super(itemView);
}
public void setParent(ViewGroup parent) {
this.parent = parent;
}
}
- Second step is to create the holder for Ad at the proper position using AdHolder. Very important to set the parent for it as shown below:
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
switch (viewType) {
case AD_VIEW_TYPE:
AdHolder adHolder = new AdHolder(adView);
adHolder.setParent(parent);
return adHolder;
default:
// your default list item
}
}
- The last step is to bind our ViewHolder with the ad
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
if (position == AD_POSITION) {
InterscrollerAdapter.bindTo(
(ViewGroup)holder.itemView,
((AdHolder)holder).parent,
position);
}
Comments
0 comments
Please sign in to leave a comment.