You are on page 1of 48

 

 
 
 
 
This manual provides a step-by-step guidance for the AdClient advertising integration to your Android applications. 
 
User Manual 
1. Preparation 
1.1​ Android Studio (or Gradle-based project) 

2. Setting Permissions in Manifest.xml File 


3. Obtaining Placement Key 
4. Integration 
4.1​ Smart Banner Ads 
Method #1:​ Declarative Description in Layout File 

Method #2:​ Imperative Creating at runtime 

4.2​ Interstitial Ads 


4.3​ Rewarded Ads 
4.4​ Native Ads 
4.4.1​ Preparation 

4.4.2​ Loading Native Ads 

4.4.3​ Native Media Ads 


4.4.4​ Showing Multiple Native Ads 

4.5​ Banner Ads 


Method #1:​ Declarative Description in Layout File 

Method #2:​ Imperative Creating at R


​ untime 

5. Targeting Parameters 
6. Debugging MRAID Ads 
7. Location Updates 
7.1 ​Requesting Location permissions 

7.2 ​Location Updates 

8. Consent 
8.1​ Preparation 

8.2​ Update consent status 

8.3​ Collect Consent 

8.4​ Storing publisher-managed consent 

8.5​ Change or revoke consent 

9. Changelog 

 
 
 
1. Preparation 

Please see the s​ dk-sample-app​ project that contains an integration sample. Third-party libraries are located in the 
libs​ directory. 

1.1 Android Studio (or Gradle-based project) 


Place the ​AdClientSDK AAR​ file (​adclient-sdk-for-android-.aar​) and another mediation libraries to the libraries' 
storage in your project (see ​build.gradle​ file in the ​sdk-sample-app​). The following code should be added to the 
build.gradle ​file: 
repositories {
jcenter()
maven { url ​"https://s3.amazonaws.com/moat-sdk-builds"​ }
maven { url ​"https://maven.google.com"​ }
maven { url ​"https://s3.amazonaws.com/avocarrot-android-builds/dist/"​ }
maven​ ​{ url​ "https://jitpack.io"​ }
}
dependencies {
implementation fileTree​(dir: 'libs', include: '**/*.jar')
implementation fileTree​(dir: 'libs', include: '**/*.aar')
implementation ​'com.android.support:multidex:1.0.3'
implementation ​'com.android.support:support-v4:28.0.0'
implementation ​'com.android.support:support-annotations:28.0.0'
implementation ​'com.android.support:appcompat-v7:28.0.0'
implementation ​'com.android.support:recyclerview-v7:28.0.0'
implementation ​'com.google.android.gms:play-services-ads:17.1.2'
implementation ​'com.google.android.gms:play-services-basement:16.1.0'
implementation ​'com.google.android.gms:play-services-location:16.1.0'
implementation ​'com.google.code.gson:gson:2.8.5'
​implementation​ ​'com.google.android.ads.consent:consent-library:1.0.7'

 
​ //if you use InLocoMedia:
​implementation ​'com.inlocomedia.android:android-sdk-ads:4.3.19'
//if you use InMobi
​implementation​ 'com.squareup.picasso:picasso:2.5.2'
​implementation​ ​'com.google.android.gms:play-services-plus:16.0.0'
//if you use Facebook:
​implementation​ ​'com.facebook.android:audience-network-sdk:5.1.0'
//if you use MyTarget
implementation​ 'com.google.android.exoplayer:exoplayer-core:2.8.3'
implementation​ 'com.google.android.exoplayer:exoplayer-hls:2.8.3'
//if you use Mobfox
implementation​ 'com.github.mobfox.MobFox-Android-SDK-Core:MobFox-Android-SDK-Core:3.6.4'
//vungle
implementation​ 'com.github.vungle:vungle-android-sdk:6.3.24'
}

AdClient SDK has the following dependencies: 


● Android Support libraries (​support-v4​, ​appcompat-v7​, r​ ecyclerview-v7​, s​ upport-annotations​).  
● Google Play Services ​Integration guide​. 
● Google Gson  

Add this code to the ​build.gradle​ file to support the dependencies: 


dependencies {
implementation ​'com.android.support:support-v4:28.0.0'
implementation ​'com.android.support:support-annotations:28.0.0'
implementation ​'com.android.support:appcompat-v7:28.0.0'
implementation ​'com.android.support:recyclerview-v7:28.0.0'
implementation ​'com.google.android.gms:play-services-ads:17.1.2'
implementation ​'com.google.android.gms:play-services-basement:16.1.0'
implementation ​'com.google.android.gms:play-services-location:16.1.0'
implementation ​'com.google.code.gson:gson:2.8.4'
}
2. Update your Manifest.xml file 

Specific permissions should be added to the A


​ ndroidManifest.xml ​file in your project: 

● Mandatory permissions (already included in aar AndroidManifest.xml): 


<uses-permission android:name=​"android.permission.INTERNET"​/>
<uses-permission android:name=​"android.permission.ACCESS_NETWORK_STATE"​/>

● AdClient  SDK  requires  metadata  from  Google  Play  Services.  Also  ​add  your  AdMob  ​App  ID  to  your  app's 
AndroidManifest.xml file by adding the <meta-data> tag shown below. You can find your App ID in the AdMob 
UI.  For  android:value  insert  your  own  AdMob  App  ID  in  quotes,  as  shown  below.  Add  the  following  to  your 
Manifest.xml f​ ile: 
<meta-data android:name=​"com.google.android.gms.version"
android:value=​"@integer/google_play_services_version"​/>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name=​"com.google.android.gms.ads.APPLICATION_ID"
android:value=​"[ADMOB_APP_ID]"
tools:replace=​"android:value"​/>

Important:​ This step is required as of Google Mobile Ads SDK version 17.0.0. Failure to add this <
​ meta-data> 
tag results in a crash with the message: "​The Google Mobile Ads SDK was initialized incorrectly.​"
● Optional permissions: 
<uses-permission android:name=​"android.permission.ACCESS_COARSE_LOCATION"​/>
<uses-permission android:name=​"android.permission.ACCESS_FINE_LOCATION"​/>
<uses-permission android:name=​"android.permission.WRITE_EXTERNAL_STORAGE"​/>
<uses-permission android:name=​"android.permission.READ_PHONE_STATE"​/>
<uses-permission android:name=​"android.permission.ACCESS_WIFI_STATE"​/>

 
 
3. Obtaining Placement Key  

The Placement Key is taken from Epom Apps dashboard or provided by your personal Epom Apps manager – it is an 
essential identifier in Epom system and the only mandatory prerequisite to get things going with the ​AdClient SDK​. 
It is recommended to have the Placement Key on hand during the implementation. 

Important:​ Use the parameters below when testing your app with our library, but don't forget to replace them 
with the actual production values supplied to you before going live:   

● AD_PLACEMENT_KEY ​for Banner: 58296e9c9472044364aa6770d8409ede 


● AD_PLACEMENT_KEY ​for Interstitial: 0928de1630a1452b64eaab1813d3af64 
● AD_PLACEMENT_KEY ​for Native Ad: ec5086312cf4959dcc54fe8a8ad15401  
● AD_PLACEMENT_KEY ​for ​Smart banner: 6e00a5adf0fb82f4d2c5f6459aa082ad 
● AD_PLACEMENT_KEY ​for ​Rewarded video: 3
​ 4e3df8021d688c7c2fec5b065a0f2c4 
● adServerUrl​: ​http://appservestar.com/ 
4. Integration 

There are two methods of adding the ​AdClientView​ t​ o your application: 

1. As a tag in the XML layout file. 


2. As API for forming and displaying the ad viewing element in your code at runtime. 

Feel free to select the one that suits you better. 

4.1 Smart Banner Ads 

Method #1: Declarative description in layout file 

In order to add​ ​SmartBannerAdView​ ​to your XML layout : 

1. Insert a reference to the ​attrs.xml​ file in your layout element:  

xmlns:app=​"http://schemas.android.com/apk/res-auto"

2. Add​ ​SmartBannerAdView​ t​ o the layout: 

<com.adclient.android.sdk.nativeads.view.SmartBannerAdView
android:id=​"@+id/native_banner_ad_view"
android:layout_width=​"match_parent"
android:layout_height=​"wrap_content"
app:adPlacementKey=​"ec5086312cf4959dcc54fe8a8ad15401"
app:adServerUrl=​"https://appservestar.com/"
app:smartBannerAdSize=​"SMART_BANNER"
app:refreshInterval=​"30"​ />

 
Here are the parameters to add to your XML layout file: 

Parameter  D
​ efinition 

adPlacementKey The key provided during the registration process. 

adServerUrl Target URL for ads requests. 

custom * Additional parameters string. 

refreshInterval * Refresh interval of 30 seconds will be applied if this parameter is omitted or the value is invalid. 
For disabling refresh interval use 0 seconds. 
Ad refresh rate in seconds: 30-90 seconds. 
In order to ensure the best user experience it is highly recommended to disable all the external 
refresh mechanisms. 
Also refresh interval can be set in dashboard and has more weight than the parameter in the 
code. 

smartBannerAdSize ** The size of the ads to display. 


* ​optional​ parameters you can add 
** list of available ​adSize v
​ alues: 

Value  Size definition (width X height)  Description 

BANNER_320x50  320 X 50 dpi  Standard Banner for Phones and 


Tablets 

LEADERBOARD_728x90  728 X 90 dpi  Leaderboard for Tablets 

SMART_BANNER  Screen width in portrait mode X  Smart Banner for Phones and Tablets 
32/50/90 dpi depending on screen 
height 

SMART_BANNER_FULL_WIDTH  Screen width X 32/50/90 dpi  Smart Banner for Phones and Tablets 
depending on screen height 
SMART_BANNER_PORTRAIT_WIDTH Screen width in portrait mode X 32  Smart Banner for Phones and Tablets 
x32  dpi 

SMART_BANNER_FULL_WIDTHx32  Screen width X 32 dpi  Smart Banner for Phones and Tablets 

SMART_BANNER_PORTRAIT_WIDTH Screen width in portrait mode X 50  Smart Banner for Phones and Tablets 
x50  dpi 

SMART_BANNER_FULL_WIDTHx50  Screen width X 50 dpi  Smart Banner for Phones and Tablets 

SMART_BANNER_PORTRAIT_WIDTH Screen width in portrait mode X 90  Smart Banner for Phones and Tablets 
x90  dpi 

SMART_BANNER_FULL_WIDTHx90  Screen width X 90 dpi  Smart Banner for Phones and Tablets 

For smart banner ads in the XML layout​ f​ ile, your sample application will be similar to this:  
<LinearLayout xmlns:android=​"http://schemas.android.com/apk/res/android"
xmlns:app=​"http://schemas.android.com/apk/res-auto"
android:orientation=​"vertical"
android:layout_width=​"fill_parent"
android:layout_height=​"fill_parent"​/>

<TextView android:layout_width=​"fill_parent"
android:layout_height=​"wrap_content"
android:text=​"@string/intro"
android:padding=​"4dip"
android:textSize=​"16sp"​ />

<com.adclient.android.sdk.nativeads.view.SmartBannerAdView
android:id=​"@+id/smart_banner_ad_view"
android:layout_width=​"match_parent"
android:layout_height=​"wrap_content"
app:adPlacementKey=​"ec5086312cf4959dcc54fe8a8ad15401"
app:adServerUrl=​"https://appservestar.com/"
app:custom=​"ch=urrrrr"
app:smartBannerAdSize=​"SMART_BANNER"
app:refreshInterval=​"30"​ />
</LinearLayout>

3. Next, in your A
​ ctivity​ ​or F
​ ragment​ ​code, declare an instance variable for your​ ​SmartBannerAdView​ ​and set up 
SmartBannerAdViewListener ​for getting callbacks.   

Method  Definition 

onBannerImpression(...) Fired when view was shown and impressions was sent 

onBannerFailed(...) Fired when no ads 

onBannerClicked(...) Fired when view was clicked 

onBannerLoading(...) Fired inprocessof loading: 


● isLoaded​ ​== false - ad not ready to use, but loading keeps going on 
● isLoaded == true - ad ready to use 

onBannerRefreshed(...) Fired when view was shown for refresh interval time and refreshed 

In your Activity’s​ ​onCreate()​ ​or your Fragment’s​ ​onCreateView(​)​ ​method call​ ​load()​ ​to f​etch and display the ad: 

public​ ​void​ ​onCreate​(Bundle savedInstanceState) {


​super​.onCreate(savedInstanceState);
setContentView(R.layout.main);
​final​ SmartBannerAdView smartBannerAdView = findViewById(R.id.smart_banner_ad_view);
smartBannerAdView.setListener(​new​ SmartBannerAdView.SmartBannerAdViewListener() {
​@Override
​public​ ​void​ ​onBannerLoading​(SmartBannerAdView banner, boolean isLoaded, String message) {}
​@Override
​public​ ​void​ ​onBannerRefreshed​(SmartBannerAdView banner, String message) {}
​@Override
​public​ ​void​ o ​ nBannerImpression​(SmartBannerAdView banner) {}
​@Override
​public​ ​void​ o ​ nBannerFailed​(SmartBannerAdView banner, String message) {}
​@Override
​public​ ​void​ o ​ nBannerClicked​(SmartBannerAdView banner) {}
});
smartBannerAdView.load();
}

To manage the​ ​SmartBannerAdView​ ​lifecycle properly, use the following Activity methods:​ ​resume(), pause(),
destroy()​:
@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (smartBannerAdView != ​null​)
smartBannerAdView.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (smartBannerAdView != ​null​)
smartBannerAdView.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (smartBannerAdView != ​null​)
smartBannerAdView.destroy();
​super​.onDestroy();
}

Method #2: Imperative creating at runtime 


In order to create​ ​SmartBannerAdView​ ​element programmatically: 

1. Prepare the configuration parameters map:  


Map<ParamType, String> params = ​new​ HashMap<ParamType , String>();
params.put(ParamsType.AD_PLACEMENT_KEY,​"ec5086312cf4959dcc54fe8a8ad15401"​);
params.put(ParamsType.REFRESH_INTERVAL,​"30"​);
params.put(ParamsType.AD_SERVER_URL,​"https://appservestar.com/"​);

Full list of parameters that can be used:  


ParamsType.AD_PLACEMENT_KEY - user placement key.
ParamsType.AD_SERVER_URL - target URL ​for​ ad requests.
ParamsType.REFRESH_INTERVAL * - time ​for​ ad refresh.
ParamsType.CUSTOM - map of additional ​parameters​(key,value pairs).
​ * Refresh interval of 30 seconds will be applied if this parameter is omitted or the value is invalid. 

For disabling refresh interval use 0 seconds. 

Ad refresh rate in seconds: 30-90 seconds. 

In order to ensure the best user experience it is highly recommended to disable all the external refresh 
mechanisms. 

Also refresh interval can be set in dashboard and has more weight than the parameter in the code.

2. Create​ ​SmartBannerAdView​ ​object using one of the following constructors: 


​ martBannerAdView​(Context context);
public​ S
public​ S​ martBannerAdView​(Context context, AttributeSet attrs);
public​ S ​ martBannerAdView​(Context context, AttributeSet attrs, ​int​ defStyle);

3. Assign created parameter map to​ ​SmartBannerAdView​ ​object:  

smartBannerAdView.setConfiguration(params);

4. Set up A
​ dSize​ ​to​ ​SmartBannerAdView​ ​object​: 

smartBannerAdView.setAdSize(AdSize.SMART_BANNER);

List of available​ ​AdSize​ ​values: 


Value  Size definition (width X height)  Description 
BANNER_320x50  320 X 50 dpi  Standard Banner for Phones 
and Tablets 
LEADERBOARD_728x90  728 X 90 dpi  Leaderboard for Tablets 
SMART_BANNER  Screen width in portrait mode X  Smart Banner for Phones and 
32/50/90 dpi depending on screen  Tablets 
height 
SMART_BANNER_FULL_WIDTH  Screen width X 32/50/90 dpi depending  Smart Banner for Phones and 
on screen height  Tablets 
SMART_BANNER_FULL_WIDTHx32  Screen width X 32 dpi  Smart Banner for Phones and 
Tablets 
SMART_BANNER_FULL_WIDTHx50  Screen width X 50 dpi  Smart Banner for Phones and 
Tablets 
SMART_BANNER_FULL_WIDTHx90  Screen width X 90 dpi  Smart Banner for Phones and 
Tablets 
SMART_BANNER_PORTRAIT_WIDTHx32  Screen width in portrait mode X 32 dpi  Smart Banner for Phones and 
Tablets 
SMART_BANNER_PORTRAIT_WIDTHx50  Screen width in portrait mode X 50 dpi  Smart Banner for Phones and 
Tablets 
SMART_BANNER_PORTRAIT_WIDTHx90  Screen width in portrait mode X 90 dpi  Smart Banner for Phones and 
Tablets 

 
5. ​ Place created​ ​SmartBannerAdView​ ​anywhere within your existing layout:  
LinearLayout myLayout = (LinearLayout) findViewById(R.id.main);
myLayout.addView(smartBannerAdView);

Set up​ S
​ martBannerAdViewListener ​for getting callbacks.   
Method  Definition 

onBannerImpression(...) Fired when view was shown and impressions was sent 

onBannerFailed(...) Fired when no ads 

onBannerClicked(...) Fired when view was clicked 

onBannerLoading(...) Fired inprocessof loading: 


● isLoaded​ ​== false - ad not ready to use, but loading keeps going on 
● isLoaded == true - ad ready to use 

onBannerRefreshed(...) Fired when view was shown for refresh interval time and refreshed 

For smart banner ads in your code, sample application will be: 

public​ ​void​ ​onCreate​(Bundle savedInstanceState) {


​super​.onCreate(savedInstanceState);
setContentView(R.layout.main);
​final​ View layout = findViewById(R.id.mainLayout);

HashMap<ParamsType, Object> configuration = ​new​ HashMap<ParamsType, Object>();


configuration.put(ParamsType.AD_PLACEMENT_KEY, ​"ec5086312cf4959dcc54fe8a8ad15401"​);
configuration.put(ParamsType.AD_SERVER_URL,​"https://appservestar.com/"​);
​final​ SmartBannerAdView smartBannerAdView = ​new​ SmartBannerAdView(context);
smartBannerAdView.setConfiguration(configuration);
smartBannerAdView.setAdSize(AdSize.SMART_BANNER);
smartBannerAdView.setListener(​new​ SmartBannerAdView.SmartBannerAdViewListener() {
​@Override
​public​ ​void​ ​onBannerLoading​(SmartBannerAdView banner, boolean isLoaded, String message) {}
​@Override
​public​ ​void​ ​onBannerRefreshed​(SmartBannerAdView banner, String message) {}
​@Override
​public​ ​void​ ​onBannerImpression​(SmartBannerAdView banner) {}
​@Override
​public​ ​void​ ​onBannerFailed​(SmartBannerAdView banner, String message) {}
​@Override
​public​ ​void​ ​onBannerClicked​(SmartBannerAdView banner) {}
});
((ViewGroup)layout).addView(smartBannerAdView);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(​new​ View.OnClickListener() {
​@Override
​public​ ​void​ ​onClick​(View view) {
smartBannerAdView.load();
}
});
}

To manage the​ ​SmartBannerAdView​ ​lifecycle properly, use the following Activity methods​: ​resume()​,​ pause()​,
destroy()​:

@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (smartBannerAdView != ​null​)
smartBannerAdView.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (smartBannerAdView != ​null​)
smartBannerAdView.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (smartBannerAdView != ​null​)
smartBannerAdView.destroy();
​super​.onDestroy();
}
4.2 Interstitial Ads 
To display Interstitial ads anywhere in your app, use the​ ​AdClientInterstitial​ ​class programmatically: 
public​ ​void​ ​onCreate​(Bundle savedInstanceState) {
s​ uper​.onCreate(savedInstanceState);
setContentView(R.layout.main);
​final​ AdClientInterstitial interstitial = ​new​ AdClientInterstitial(this);
HashMap<ParamsType, Object> configuration = ​new​ HashMap<ParamsType, Object>();
configuration.put(ParamsType.AD_PLACEMENT_KEY, ​"0928de1630a1452b64eaab1813d3af64"​);
configuration.put(ParamsType.ADTYPE, AdType.INTERSTITIAL.toString());
configuration.put(ParamsType.AD_SERVER_URL,​"http://appservestar.com/"​);
interstitial.setConfiguration(configuration);
interstitial.addClientAdListener(​new​ ClientAdListener() {
​@Override
​public​ ​void​ ​onReceivedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onFailedToReceiveAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onClickedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onLoadingAd​(AbstractAdClientView adClientView, String message) {
​if​ (interstitial.isAdLoaded()) {
interstitial.show();
}
}
​@Override
​public​ ​void​ ​onClosedAd​(AbstractAdClientView adClientView) {}
});
interstitial.load();
}
 

To manage the​ ​AdClientInterstitial​ ​lifecycle properly, use the following Activity methods​:​ ​resume()​,
pause()​, ​destroy()​:
@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (interstitial != ​null​)
interstitial.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (interstitial != ​null​)
interstitial.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (interstitial != ​null​)
interstitial.destroy();
​super​.onDestroy();
}

4.3 Rewarded Ads 

To display Rewarded ads anywhere in your app, use the​ ​AdClientRewarded​ ​class programmatically: 

​final​ AdClientRewarded rewarded = ​new​ AdClientRewarded(context);


HashMap<ParamsType, Object> configuration = ​new​ HashMap<ParamsType, Object>();
configuration.put(ParamsType.AD_PLACEMENT_KEY, ​"34e3df8021d688c7c2fec5b065a0f2c4"​);
configuration.put(ParamsType.ADTYPE, AdType.REWARDED.toString());
configuration.put(ParamsType.AD_SERVER_URL,​"http://appservestar.com/"​);
rewarded.setConfiguration(configuration);
rewarded.addClientAdListener(​new​ ClientRewardedAdListener() {
​@Override
​public​ ​void​ ​onReceivedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onFailedToReceiveAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onClickedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onLoadingAd​(AbstractAdClientView adClientView, String message) {
​if​ (rewarded.isAdLoaded()) {
rewarded.show();
}
}
​@Override
​public​ ​void​ ​onRewarded​() {}
​@Override
​public​ ​void​ ​onClosedAd​(AbstractAdClientView adClientView) {}
});

Button button = (Button) findViewById(R.id.button);


button.setOnClickListener(​new​ View.OnClickListener() {
​@Override
​public​ ​void​ ​onClick​(View view) {
rewarded.load();
}
});
To manage the​ ​AdClientRewarded​ ​lifecycle properly, use the following Activity methods:​ ​resume​(), ​pause​(),
destroy​()​:
@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (rewarded!= ​null​)
rewarded.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (rewarded!= ​null​)
rewarded.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (rewarded!= ​null​)
rewarded.destroy();
​super​.onDestroy();
}

4.4 Native Ads 

Native ads give you the control to design the perfect ad units for your app. With our Native ads, you can determine 
the look and feel, size and location of your ads. You decide how the ads will be formatted, so they can seamlessly fit 
in your application. 

4.4.1 Preparation 

You should create an XML layout for Native ads. It defines how an ad will be displayed in your app. It's up to you to 
design the layout settings that will make the ad fit your app seamlessly. 

Before integration, please check our best practices page for native ads 
https://apps.epom.com/formats/native-best-practices​. 

The XML should meet the following requirements: 

● The example layout can be found below. It includes: 


● Several​ ​TextView​ i​ tems for title, subtitle, and description text. 
● One​ ​RatingBar​.
● Several A
​ dClientIconView​ ​items for an icon image, ad creative itself and privacy icon image. 
● One B
​ utton​ ​item for call to action advertiser text 

​Location:​ r​ es/layout/native_ad_layout.xml 

<RelativeLayout ...>
<com.adclient.android.sdk.nativeads.view.AdClientIconView
android:id=​"@+id/native_ad_icon_image"
... />
<com.adclient.android.sdk.nativeads.view.AdClientMediaView
android:id=​"@+id/native_ad_media_view"
... />
<TextView android:id=​"@+id/native_ad_title_text"
... />
<TextView android:id=​"@+id/native_ad_subtitle_text"
... />
<TextView android:id=​"@+id/native_ad_description_text"
... />
<TextView android:id=​"@+id/native_ad_warning_text"
... />
<TextView android:id=​"@+id/native_ad_age_text"
android:padding=​"10dp"
... />
<RatingBar
android:id=​"@+id/native_ad_rating_bar"
android:isIndicator=​"true"
android:max=​"5"
.../>
<Button
android:id=​"@+id/native_ad_call_to_action_button"
.../>
<TextView android:id=​"@+id/native_ad_sponsored_text"
android:text=​"Sponsored"
... />
<com.adclient.android.sdk.nativeads.view.AdClientIconView
android:id=​"@+id/native_ad_privacy_information_icon"
android:layout_width=​"40dp"
android:layout_height=​"40dp"
android:padding=​"10dp"
... />
</RelativeLayout>
Next, create an​ ​AdClientNativeAdBinder ​object. It should bind the XML layout and the ad content. 

AdClientNativeAdBinder binder = ​new​ AdClientNativeAdBinder(R.layout.native_ad_layout);


binder.bindView(AdClientNativeAdBinder.ViewType.TITLE_TEXT_VIEW, R.id.native_ad_title_text);
binder.bindView(AdClientNativeAdBinder.ViewType.SUBTITLE_TEXT_VIEW, R.id.native_ad_subtitle_text);
binder.bindView(AdClientNativeAdBinder.ViewType.DESCRIPTION_TEXT_VIEW, R.id.native_ad_description_text);

binder.bindView(AdClientNativeAdBinder.ViewType.ICON_VIEW, R.id.native_ad_icon_image);
binder.bindView(AdClientNativeAdBinder.ViewType.MEDIA_VIEW, R.id.native_ad_media_view);

binder.bindView(AdClientNativeAdBinder.ViewType.CALL_TO_ACTION_VIEW,
R.id.native_ad_call_to_action_button);
binder.bindView(AdClientNativeAdBinder.ViewType.SPONSORED_TEXT_VIEW, R.id.native_ad_sponsored_text);
binder.bindView(AdClientNativeAdBinder.ViewType.PRIVACY_ICON_VIEW,
R.id.native_ad_privacy_information_icon);
binder.bindView(AdClientNativeAdBinder.ViewType.RATING_VIEW, R.id.native_ad_rating_bar);
binder.bindView(AdClientNativeAdBinder.ViewType.WARNING_TEXT_VIEW, R.id.native_ad_warning_text);
binder.bindView(AdClientNativeAdBinder.ViewType.AGE_TEXT_VIEW, R.id.native_ad_age_text);
​Optional​:​ Specify the clickable subviews for better control (by default, all views are clickable): 
List<Integer> clickItems = ​new​ ArrayList<>();
clickItems.add(R.id.call_to_action_button);
binder.setClickableItems(clickItems);

Create​ ​AdClientNativeAdRenderer​ ​instance for rendering Native Ad views after adding to your app content: 
AdClientNativeAdRenderer renderer = ​new​ AdClientNativeAdRenderer(context, binder);
renderer.setShowImagesAutomatically(​true​); ​//by default enabled
ClientNativeAdImageListener clientNativeAdImageListener = ​new​ ClientNativeAdImageListener() {
​@Override
​public​ ​void​ ​onShowImageFailed​(ImageView imageView, String uri, ImageDisplayError error) {
​// error of loading image, you can try to load image by our image loading implementation
​// or use your own or 3rd party library (Volley, UniversalImageLoader, Glide, Picasso etc)
AdClientNativeAd.displayImage(imageView, uri, ​this​);
}
​@Override
​public​ ​void​ ​onNeedToShowImage​(ImageView imageView, String uri) {
​// called when automatic loading of images disabled by renderer.setShowImagesAutomatically(false)
​// you can try to load image by our image loading implementation
​// or use your own or 3rd party library (Volley, UniversalImageLoader, Glide, Picasso etc)
AdClientNativeAd.displayImage(imageView, uri, ​this​);
}

​@Override
​public​ ​void​ ​onShowImageSuccess​(ImageView imageView, String uri) {}
};

renderer.setClientNativeAdImageListener(clientNativeAdImageListener);

NOTE​:​ Please avoid creating​ ​AdClientNativeAdRenderer​ i​ nstances for every​ A


​ dClientNativeAd​ ​object 
instance. For better performance you must use the same ​AdClientNativeAdRenderer​ i​ nstance for all 
AdClientNativeAd​ i​ nstances with the same layout​. 

4.4.2 Loading Native Ads 

Create and set up​ ​AdClientNativeAd​ ​an​ ​AdClientNativeAd ​object instance (see example application class 
NativeAdsSimpleActivity​): 
HashMap<ParamsType, Object> configuration = ​new​ HashMap<ParamsType,Object>();
configuration.put(ParamsType.AD_SERVER_URL,​"http://appservestar.com/"​);
configuration.put(ParamsType.AD_PLACEMENT_KEY, ​"ec5086312cf4959dcc54fe8a8ad15401"​);
configuration.put(ParamsType.REFRESH_INTERVAL, ​30​);
AdClientNativeAd adClientNativeAd = ​new​ AdClientNativeAd(context, configuration, renderer);

Parameter  Definition 

adPlacementKey The key provided during the registration process. 


adServerUrl Target URL for ad requests. 

refreshInterval ● Refresh interval of 0 seconds will be applied if this parameter is omitted or the value 
is invalid. 
● For disabling refresh interval use 0 seconds. 
● Ad refresh rate in seconds: 30-90 seconds. 
● In order to ensure the best user experience it is highly recommended to disable all 
the external refresh mechanisms. 

NOTE:​ R
​ efresh interval implementation of​ ​AdClientNativeAd​ ​works​ ONLY f​ or fully loaded and showed ads.  

If you haven't received any ads and so they were not loaded – you should think out and make the mechanism 
for the next load. The main point – is that refresh interval will work only after the ad is loaded and showed.
Set up​ ​ClientNativeAdListener​ ​for getting callbacks and load ad: 

ClientNativeAdListener clientNativeAdListener = ​new​ ClientNativeAdListener() {


​@Override
​public​ ​void​ ​onImpressionAd​(AdClientNativeAd adClientNativeAd, ​boolean​ callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onFailedToReceiveAd​(AdClientNativeAd adClientNativeAd, String message, ​boolean
callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onClickedAd​(AdClientNativeAd adClientNativeAd, ​boolean​ callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onLoadingAd​(​final​ AdClientNativeAd adClientNativeAd, boolean isLoaded, String message,
boolean​ callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onRefreshedAd​(AdClientNativeAd adClientNativeAd, String message, ​boolean
callbackFromUIThread){}
}
adClientNativeAd.setClientNativeAdListener(clientNativeAdListener);
adClientNativeAd.load();
 

Method  Definition 
onImpressionAd(...) Fired when view was shown and impressions was sent 

onFailedToReceiveAd(...) Fired when no ads 

onClickedAd(...) Fired when view was clicked 

onLoadingAd(...) Fired in process of loading: 


● isLoaded == false​ ​– ad not ready to use, but loading keeps going on 
● isLoaded== true​ ​–​ ad ready to use 

onRefreshedAd(...) Fired when view was shown for refresh interval time and refreshed 

NOTE:​ F
​ or better performance you must use A
​ ctivity context​ for loading native ads. 

For p
​ refetching ads​ in your A
​ pplication​ ​class ​see example application classes:​ ​SampleApplication​,
NativeAdsFromApplicationLoaderActivity​ ​and​ ​NativeAdsFromApplicationActivity​.

Be careful If you prefer to use A


​ pplication context​ when you interacting with Main UI Thread from 
ClientNativeAdListener​. ​Check​ ​callbackFromUIThread​ ​parameter for the information about current execution 
thread for avoiding crashes​. W
​ hen​ ​callbackFromUIThread == false​ ​you must run your code in Main UI Thread. 
For these purposes, you can use our helper method​ ​AdClientNativeAd​.​executeOnUiThread (Activity context,
Runnable action)​. F
​ or example: 

@Override
public​ ​void​ ​onLoadingAd​(​final​ AdClientNativeAd adClientNativeAd, ​final​ boolean isLoaded, String message,
boolean​ callbackFromUIThread) {
AdClientNativeAd.executeOnUiThread(context, ​new​ Runnable() {
​@Override
​public​ ​void​ ​run​() {
Log.d(​"AdClientSdk"​, ​"onLoadingAd: loaded = "​ + isLoaded);
​if​ (isLoaded) {
​View nativeAdView = adClientNativeAd.getView(context);
adClientNativeAd.renderView(nativeAdView);
adClientNativeAd.registerImpressionsAndClicks(nativeAdView);
​adsContainerLayout.addView(nativeAdView);
}
}
});
}
To manage the​ ​AdClientNativeAd​ ​lifecycle ​properly, use the following Activity methods:​ ​resume​(), ​pause​(),
destroy​():
@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (adClientNativeAd != ​null​)
adClientNativeAd.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (adClientNativeAd != ​null​)
adClientNativeAd.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (adClientNativeAd != ​null​) {
adClientNativeAd.destroy();
adClientNativeAd = ​null​;
}
​super​.onDestroy();
}

To show the result, create rendered view and prepare it for impressions tracking. 
Please, follow the order for calling methods:  
View nativeAdView = adClientNativeAd.getView(activity);
adClientNativeAd.renderView(nativeAdView);
adClientNativeAd.registerImpressionsAndClicks(nativeAdView);
nativeAdContainerLinearLayout.removeAllViews();
nativeAdContainerLinearLayout.addView(nativeAdView);
U​se a
​ dClientNativeAd.getViewByType(View view, AdClientNativeAdBinder.ViewType type)​ to customize 
subview attributes on prepared view before (i.e.:​ ​typeface​, ​color​, ​size​ ​, etc.). For example: 
TextView titleTextView = (TextView)adClientNativeAd.getViewByType(nativeAdView,
AdClientNativeAdBinder.ViewType.TITLE_TEXT_VIEW);
if​(titleTextView!=​null​){
titleTextView.setTypeface(...);
titleTextView.setTextColor(...);
}
 
4.4.3 Native Media Ads 

For displaying media ads, it is recommended to use the​ ​AdClientMediaView​ ​which can display both image and 
video assets. 

Create layout: 

L
​ ocation:​ r​ es/layout/native_ad_layout.xml 

<RelativeLayout ...>
<com.adclient.android.sdk.nativeads.view.AdClientMediaView
android:id=​"@+id/native_ad_media_view"
android:background=​"@null"
... />
<com.adclient.android.sdk.nativeads.view.AdClientIconView
android:id=​"@+id/native_ad_icon"
... />
<TextView android:id=​"@+id/native_ad_title_text"
... />
<TextView android:id=​"@+id/native_ad_subtitle_text"
... />
<TextView android:id=​"@+id/native_ad_description_text"
... />
<TextView android:id=​"@+id/native_ad_warning_text"
... />
<TextView android:id=​"@+id/native_ad_age_text"
android:padding=​"10dp"
... />
<RatingBar
android:id=​"@+id/native_ad_rating_bar"
android:isIndicator=​"true"
android:max=​"5"​ .../>
<Button
android:id=​"@+id/native_ad_call_to_action_button"
.../>
<TextView android:id=​"@+id/native_ad_sponsored_text"
android:text=​"Sponsored"
... />
<com.adclient.android.sdk.nativeads.view.AdClientIconView
android:id=​"@+id/native_ad_privacy_information_icon"
android:layout_width=​"40dp"
android:layout_height=​"40dp"
android:padding=​"10dp"
android:background=​"@null"
... />
</RelativeLayout>

Next, create an ​AdClientNativeAdBinder​ ​object. It should bind the XML layout and the ad content. 
AdClientNativeAdBinder binder = ​new​ AdClientNativeAdBinder(R.layout.native_ad_layout);
binder.bindView(AdClientNativeAdBinder.ViewType.TITLE_TEXT_VIEW, R.id.native_ad_title_text);
binder.bindView(AdClientNativeAdBinder.ViewType.SUBTITLE_TEXT_VIEW, R.id.native_ad_subtitle_text);
binder.bindView(AdClientNativeAdBinder.ViewType.DESCRIPTION_TEXT_VIEW, R.id.native_ad_description_text);
binder.bindView(AdClientNativeAdBinder.ViewType.ICON_VIEW, R.id.native_ad_icon);
binder.bindView(AdClientNativeAdBinder.ViewType.MEDIA_VIEW, R.id.native_ad_media_view);
binder.bindView(AdClientNativeAdBinder.ViewType.CALL_TO_ACTION_VIEW,
R.id.native_ad_call_to_action_button);
binder.bindView(AdClientNativeAdBinder.ViewType.SPONSORED_TEXT_VIEW, R.id.native_ad_sponsored_text);
binder.bindView(AdClientNativeAdBinder.ViewType.PRIVACY_ICON_VIEW,
R.id.native_ad_privacy_information_icon);
binder.bindView(AdClientNativeAdBinder.ViewType.RATING_VIEW, R.id.native_ad_rating_bar);
binder.bindView(AdClientNativeAdBinder.ViewType.WARNING_TEXT_VIEW, R.id.native_ad_warning_text);
binder.bindView(AdClientNativeAdBinder.ViewType.AGE_TEXT_VIEW, R.id.native_ad_age_text);

Create A
​ dClientNativeAdRenderer​ ​instance for rendering Native Ad views after adding to your app content: 
AdClientNativeAdRenderer renderer = ​new​ AdClientNativeAdRenderer(context, binder);
renderer.setShowImagesAutomatically(​true​); ​//by default enabled
renderer.setClientNativeAdImageListener(clientNativeAdImageListener);
 
Cre​ate and set up​ ​AdClientNativeAd​ ​an​ ​AdClientNativeAd ​object instance 
HashMap<ParamsType, Object> configuration = ​new​ HashMap<ParamsType,Object>();
configuration.put(ParamsType.AD_SERVER_URL,​"http://appservestar.com/"​);
configuration.put(ParamsType.AD_PLACEMENT_KEY, ​"ec5086312cf4959dcc54fe8a8ad15401"​);
configuration.put(ParamsType.REFRESH_INTERVAL, ​30​);
AdClientNativeAd adClientNativeAd = ​new​ AdClientNativeAd(context, configuration, renderer);
 
Set up​ ​ClientNativeAdListener​ f​ or getting callbacks and load ad:  
ClientNativeAdListener clientNativeAdListener = ​new​ ClientNativeAdListener() {
​@Override
​public​ ​void​ ​onImpressionAd​(AdClientNativeAd adClientNativeAd, ​boolean​ callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onFailedToReceiveAd​(AdClientNativeAd adClientNativeAd, String message, ​boolean
callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onClickedAd​(AdClientNativeAd adClientNativeAd, ​boolean​ callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onLoadingAd​(​final​ AdClientNativeAd adClientNativeAd, final boolean isLoaded, String
message, ​boolean​ callbackFromUIThread) {}
​@Override
​public​ ​void​ ​onRefreshedAd​(AdClientNativeAd adClientNativeAd, String message, ​boolean
callbackFromUIThread){}
}
adClientNativeAd.setClientNativeAdListener(clientNativeAdListener);
adClientNativeAd.load();
To manage the​ ​AdClientNativeAd​ l​ ifecycle p
​ roperly, use the following Activity methods: r
​ esume​(), ​pause​(),
destroy​():
@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (adClientNativeAd != ​null​)
adClientNativeAd.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (adClientNativeAd != ​null​)
adClientNativeAd.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (adClientNativeAd != ​null​) {
adClientNativeAd.destroy();
adClientNativeAd = ​null​;
}
​super​.onDestroy();
}

For tracking video events set ​ClientMediaControllerCallback​:


adClientNativeAd.setClientMediaControllerCallback(​new​ ClientMediaControllerCallback() {
​@Override
​public​ ​void​ ​onVideoStart​() {}
​@Override
​public​ ​void​ ​onVideoPlay​() {}
​@Override
​public​ ​void​ ​onVideoPause​() {}
​@Override
​public​ ​void​ ​onVideoCompleted​() {}
​@Override
​public​ ​void​ ​onEnterFullscreen​() {}
​@Override
​public​ ​void​ ​onExitFullscreen​() {}
});

To show the result, create rendered view and prepare it for impressions tracking. 
Please, follow the order for calling methods:  
View nativeAdView = adClientNativeAd.getView(context);
adClientNativeAd.renderView(nativeAdView);
adClientNativeAd.registerImpressionsAndClicks(nativeAdView);
nativeAdContainerLinearLayout.removeAllViews();
nativeAdContainerLinearLayout.addView(nativeAdView);

4.4.4 Showing Multiple Native Ads 

To show more than one native ad you can use your own logic with a preloaded collection of ​AdClientNativeAd
objects or our implementation of basic adapters from the ​SDK-sample-app​: 

● AdClientNativeAdBaseAdapter​ ​– ​for ​BaseAdapter​ implementations (see example class


NativeAdsListActivity​)
● AdClientNativeAdRecyclerViewAdapter ​& ​AdClientNativeAdRecyclerViewHolder​ ​– for 
RecyclerViewAdapter​ ​implementation (see example class​ ​NativeAdsRecyclerViewActivity​) 

Both​ ​AdClientNativeAdBaseAdapter ​& ​AdClientNativeAdRecyclerViewAdapter​ ​use 


AdClientNativeAdPositioning​.​ClientPositioning​ ​–​ a
​ positioning object for specifying where ads will be placed 
in your stream. For example: 
AdClientNativeAdPositioning.ClientPositioning positioning =
AdClientNativeAdPositioning.clientPositioning().addFixedPosition(​5​)
.addFixedPosition(​30​)
.enableRepeatingPositions(​20​);

Important:​ A
​ fter you finish the integration, please provide a mockup with native ads in your app to an Epom 
Apps Manager or forward it to ​apps@epom.com​. 
 
4.5 Banner Ads 

Method #1: Declarative Description in Layout File 

In order to add AdClientView to your XML layout : 


1. Add attributes set in the XML layout for this view into res/values (attrs.xml) by pasting the following configuration 
parameters into your a
​ ttrs.xml​ file: 
<resources>
<declare-styleable name=​"com.adclient.app.configuration"​>
<attr name=​"adPlacementKey"​ format=​"string"​/>
<attr name=​"refreshInterval"​ format=​"integer"​/>
<attr name=​"adType"​ format=​"string"​/>
<attr name=​"viewBackground"​ format=​"string"​/>
<attr name=​"custom"​ format=​"string"​/>
<attr name=​"adServerUrl"​ format=​"string"​/>
<attr name=​"textAlign"​ format=​"string"​/>
</declare-styleable>
</resources>
Here are the ​mandatory​ parameters to add to your XML layout file: 

Parameter  Definition 

adPlacementKey The key provided during the registration process. 

adServerUrl Target URL for ads requests. 


 
Additionally, there are ​optional​ parameters you can add to your requests: 

Parameter  Definition 

refreshInterval Refresh interval of 30 seconds will be applied if this parameter is omitted or the value is 
invalid. 
For disabling refresh interval use 0 seconds. 
Ad refresh rate in seconds: 30-90 seconds. 
Not used for Interstitial ads. 
In order to ensure the best user experience it is highly recommended to disable all the 
external refresh mechanisms. 

adType* The type of the ads to display. Supported values: 


BANNER_320X50 
BANNER_300X250 
BANNER_728X90 
INTERSTITIAL 
REWARDED 
If the banner size is not specified, B
​ ANNER_320X50​ ​will be shown by default. 

viewBackground Background color of the ad display area (text value). I.e.: 

app:viewBackground = ​"magenta"
Defaults value: ​black  

custom Additional parameters string. 

textAlign Webview text alignment parameter. Supported values: 


left
center
right

2. Insert a reference to the ​attrs.xml​ file in your layout element: add the x
​ mlns​ line that includes your package 
name specified in ​AndroidManifest.xml​. I.e., for the c
​ om.adclient.sample p
​ ackage the line will be: 
xmlns:app = ​"http://schemas.android.com/apk/res/com.adclient.sample"
3. Add A
​ dClientView​ ​to the layout: 

B
​ anner​: 
<com.adclient.android.sdk.view.AdClientView
android:id=​"@+id/adClientView"
android:layout_width=​"fill_parent"
android:layout_height=​"wrap_content"
app:adPlacementKey=​"58296e9c9472044364aa6770d8409ede"
app:refreshInterval=​"30"
app:adType=​"BANNER_320X50"
app:adServerUrl =​"http://appservestar.com/"​ />
For banner ads in the XML layout​ f​ ile, your sample application will be similar to this: 
<?xml version=​"1.0"​ encoding=​"utf-8"​?>
<LinearLayout xmlns:android=​"http://schemas.android.com/apk/res/android"
xmlns:app=​"http://schemas.android.com/apk/res/com.adclient.sample"
android:orientation=​"vertical"
android:layout_width=​"fill_parent"
android:layout_height=​"fill_parent"​/>
<TextView android:layout_width=​"fill_parent"
android:layout_height=​"wrap_content"
android:text=​"@string/intro"
android:textSize=​"16sp"​ />
<com.adclient.android.sdk.view.AdClientView
android:id=​"@+id/adClientView"
android:layout_width=​"fill_parent"
android:layout_height=​"wrap_content"
app:adPlacementKey=​"58296e9c9472044364aa6770d8409ede"
app:adServerUrl =​"http://appservestar.com/"
app:refreshInterval=​"30"
app:adType=​"BANNER_320X50"​ />
<Button android:text=​"@+id/Button01"
android:layout_width=​"wrap_content"
android:layout_height=​"wrap_content"​>
</Button>
</LinearLayout>
4. Next, in your A
​ ctivity​ or F
​ ragment​ code, declare an instance variable for your ​AdClientView​. In your Activity’s 
onCreate()​ ​or your Fragment’s​ ​onCreateView()​ ​method call​ ​load()​ ​to fetch and display the ad: 
public​ ​void​ ​onCreate​(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
setContentView(R.layout.main);
​final​ AdClientView adClientView = findViewById(R.id.adClientView);
adClientView.addClientAdListener(​new​ ClientAdListener() {
​@Override
​public​ ​void​ ​onReceivedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onFailedToReceiveAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onClickedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onLoadingAd​(AbstractAdClientView adClientView, String message) {}
​@Override
​public​ ​void​ ​onClosedAd​(AbstractAdClientView adClientView) {}
});
adClientView.load();
}

To manage the​ ​AdClienView​ ​lifecycle properly, use the following Activity methods:​ ​resume()​, ​pause()​,
destroy()​:
@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (adClientView != ​null​)
adClientView.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (adClientView != ​null​)
adClientView.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (adClientView != ​null​)
adClientView.destroy();
​super​.onDestroy();
}

Method #2: Imperative Creating at Runtime 


In order to create A
​ dClientView​ e
​ lement programmatically: 
1. Prepare the configuration parameters map: 
Map<ParamType , String> params = ​new​ HashMap<ParamType , String>();
params.put(ParamsType.AD_PLACEMENT_KEY,​"58296e9c9472044364aa6770d8409ede"​);
params.put(ParamsType.REFRESH_INTERVAL,​"30"​);
params.put(ParamsType.ADTYPE,​"BANNER_320X50"​);
params.put(ParamsType.TEXT_ALIGN,​"center"​);
params.put(ParamsType.AD_SERVER_URL,​"http://appservestar.com/"​);

Full list of parameters that can be used: 


ParamsType.AD_PLACEMENT_KEY​ ​– user key. 
ParamsType.REFRESH_INTERVAL​ ​– time ​for​ ad refresh. 
ParamsType.ADTYPE​ ​– specific ad type. 
ParamsType.CUSTOM​ ​– map of additional parameters(key,value pairs). 
ParamsType.AD_SERVER_URL​ ​– target URL f​ or​ ad requests. 
ParamsType.TEXT_ALIGN​ ​– align of text in webview. 

2. Create A
​ dClientView​ ​object using one of the following constructors: 
​ dClientView​(Context context);
public​ A
public​ A​ dClientView​(Context context, AttributeSet attrs);
public​ A ​ dClientView​(Context context, AttributeSet attrs, ​int​ defStyle);

3. Assign created parameter map to​ ​AdClientView​ ​object: 


adClientView.setConfiguration(params);
4. ​ Place created​ ​adClientView​ ​anywhere within your existing layout: 
LinearLayout myLayout = (LinearLayout) findViewById(R.id.main);
myLayout.addView(adClientView);

For banner ads in your code, sample application will be: 


public​ ​void​ ​onCreate​(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
setContentView(R.layout.main);
​final​ View layout = findViewById(R.id.mainLayout);
​final​ AdClientView adClientView = ​new​ AdClientView(context);
HashMap<ParamsType, Object> configuration = ​new​ HashMap<ParamsType, Object>();
configuration.put(ParamsType.AD_PLACEMENT_KEY, ​"58296e9c9472044364aa6770d8409ede"​);
configuration.put(ParamsType.ADTYPE,​"BANNER_320X50"​);
configuration.put(ParamsType.AD_SERVER_URL,​"http://appservestar.com/"​);
adClientView.setConfiguration(configuration);
adClientView.addClientAdListener(​new​ ClientAdListener() {
​@Override
​public​ ​void​ ​onReceivedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onFailedToReceiveAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onClickedAd​(AbstractAdClientView adClientView) {}
​@Override
​public​ ​void​ ​onLoadingAd​(AbstractAdClientView adClientView, String message) {}
​@Override
​public​ ​void​ ​onClosedAd​(AbstractAdClientView adClientView) {}
});
((ViewGroup)layout).addView(adClientView);

findViewById(R.id.button).setOnClickListener(​new​ View.OnClickListener() {
​@Override
​public​ ​void​ ​onClick​(View view) {
adClientView.load();
}
});
}

To manage the​ ​AdClienView​ ​lifecycle properly, use the following Activity methods: r
​ esume()​, ​pause()​,
destroy()​:
@Override
protected​ ​void​ ​onResume​() {
​super​.onResume();
​if​ (adClientView != ​null​)
adClientView.resume();
}
@Override
protected​ ​void​ ​onPause​() {
​if​ (adClientView != ​null​)
adClientView.pause();
​super​.onPause();
}
@Override
protected​ ​void​ ​onDestroy​() {
​if​ (adClientView != ​null​)
adClientView.destroy();
​super​.onDestroy();
}

   
5. Targeting Parameters 

To optimize the advertising performance it is possible to pass the targeting parameters to the ad request 
configurations. For example: 

TargetingParams targetingParams = ​new​ TargetingParams();


targetingParams.setAge(​29​);
targetingParams.setGender(Gender.MALE);
targetingParams.setBirthday(​new​ GregorianCalendar(​1987​, ​6​, 6
​ ​).getTime());
targetingParams.setCity(​"New York"​);
targetingParams.addSearchQuery(​"restaurant New York"​);
targetingParams.setForChildren(​false​);
targetingParams.setForFamily(​false​);

Map<ParamType , String> params = ​new​ HashMap<ParamType , String>();


params.put(ParamsType.AD_PLACEMENT_KEY,​"58296e9c9472044364aa6770d8409ede"​);
params.put(ParamsType.AD_SERVER_URL,​"http://appservestar.com/"​);
params.put(ParamsType.TARGETING_PARAMS, targetingParams);

List of available parameters: 


Age If your app already knows a user's Age, it can provide that information for targeting purposes. 

Birthday If your app already knows a user's Birthday, it can provide that information for targeting purposes. 

Birth year If your app already knows a user's Birth Year, it can provide that information for targeting purposes. 

Gender If your app already knows a user's Gender, it can provide that information for targeting purposes. 

Language If your app already knows a user's Language, it can provide that information targeting purposes. 

Location If your app already knows a user's Location, it can provide that information targeting purposes. 

City If your app already knows a user's City, it can provide that information targeting purposes. 
Region If your app already knows a user's Language, it can provide that information targeting purposes. 

Keywords Tags set by the app developer that describe the type of content (e.g.: ​cars, news, restaurants, new 
york, etc.​) 

Categories Tags set by the app developer that describe the type of app categories (e.g., M
​ usic, Sport​...) 

Interests If your app already knows a user's interests, it can provide that information targeting purposes (e.g., 
music, video, photo​...). 

Search queries A search term or keywords entered by the user (e.g., restaurant New York). For example, if there is a 
search bar in your app, when end users search for ​restaurant​, you can pass the query string to 
search terms. 

Child-directed For purposes of the ​Children's Online Privacy Protection Act (COPPA)​, there is a setting called "tag 
setting for child-directed treatment" 

Designed for If you have opted your app in to G


​ oogle Play's Designed for Families​ program and you show ads 
Families in your app, you need to ensure those ads comply with the D
​ esigned for Families​ program 
requirements and ad policies. 

6. Debugging MRAID Ads 

With AdClient SDK for Android it is possible to debug custom MRAID-powered ads. Use​ ​mraid.logEntry(message) 
at any place in your Rich Media Banner to pass the information to Android logging facility. 

   
7. Location Updates 

AdClient SDK for Android allows controling location updates via API by retrieving the information from users' 
devices. 

Use the L
​ ocationWatcher​ ​interface to access location update management methods: 

● watch()​ – ensures that coordinates of the user's device are sent along with every ad request; boolean value. 

● unWatch()​ – removes location listener, no coordinates will be requested or sent with the ad requests; 
boolean value.  

final​ AdClientView banner = (AdClientView) findViewById(R.id.bannerView);


banner.getLocationWatcher().unWatch();

These methods are called automatically when the visibility of the application window changes, so they can not be 
used to stop location updates on the permanent basis. To change the location update methods and intervals 
permanently use: 

Map<String, LocationWatcher.LocationProviderInfo> locationProviderMap =


banner.getLocationWatcher().getLocationProviderMap();

For instance, to set location update interval – which is one hour by default – to 5 seconds for the network provider, 
and to 10 minutes for the GPS provider: 

locationProviderMap.get(LocationManager.NETWORK_PROVIDER).setMinTime(​5000​);
locationProviderMap.get(LocationManager.GPS_PROVIDER).setMinTime(​600000​);

​ ocationProviderMap.clear()​ for each banner. 


To disable location updates completely, call l
8. Consent 

Under the Google ​EU User Consent Policy​, you must make certain disclosures to your users in the European 
Economic Area (EEA) and obtain their consent to use cookies or other local storage, where legally required, and to 
use personal data (such as AdID) to serve ads. This policy reflects the requirements of the EU ePrivacy Directive and 
the General Data Protection Regulation (GDPR). 

8.1 Preparation 

Place the EpomApps Consent library AAR file (epomapps-android-consent-*.aar) to the libraries' storage in your 
project (see build.gradle file in the sdk-sample-app). The following code should be added to the build.gradle file: 

repositories {
google()
jcenter()
flatDir {
dirs ​'libs'
}
}
dependencies {
​ ​implementation ​'com.google.android.ads.consent:consent-library:1.0.7'
}

8.2 Update Consent Status 

It is recommended that you determine the status of a user's consent at ​every app launch​. To do this, call 
requestConsentStatusUpdate() ​on an instance of C
​ onsentInformationManager​:

ConsentInformationManager consentInformationManager = ConsentInformationManager.getInstance(context);


consentInformationManager.requestConsentStatusUpdate(​new​ OnConsentStatusUpdateListener() {
​@Override
​public​ ​void​ ​onConsentStateUpdated​(ConsentStatus consentStatus, LocationStatus locationStatus) {
​// User's consent state information successfully updated.
}
​@Override
​public​ ​void​ ​onFailed​(String message) {}
});

If the consent information is successfully updated, the updated consent status is provided via the 
onConsentStateUpdated()​ method of the O
​ nConsentStatusUpdateListener​. 

The returned consent status may have the values listed below:
ConsentStatus  Definition 

ConsentStatus.UNKNOWN The user has neither granted nor declined consent for personalized or 
non-personalized ads. 

ConsentStatus.NON_PERSONALIZED The user has granted consent for non-personalized ads. 

ConsentStatus.PERSONALIZED The user has granted consent for personalized ads. 

The returned location status may have the values listed below: 
Location Status  Definition 

LocationStatus.UNKNOWN No information about user location. Try to request consent status. 

LocationStatus.NOT_IN_EEA The user is not located in the European Economic Area and consent is not 
required under the E​ U User Consent Policy 

LocationStatus.IN_EEA The user is located in the European Economic Area and consent is 
required under the E​ U User Consent Policy 
8.3 Collect Consent 
The ​EpomApps​ rendered consent form is a full-screen configurable form that displays over your app content. 
Consent form is configured and displayed using the C
​ onsentForm​ ​class. The following code demonstrates how to 
build a C
​ onsentForm​ ​with all consent options:
ConsentForm consentForm = ConsentForm.createBuilder(​this​)
.withListener(​new​ ConsentFormListener() {
​@Override
​public​ ​void​ ​onConsentFormLoaded​() {
​// Consent form loaded successfully.
}
​@Override
​public​ ​void​ ​onConsentFormError​(String reason) {
​// Consent form error.
}
​@Override
​public​ ​void​ ​onConsentFormOpened​() {
​// Consent form was displayed.
}
​@Override
​public​ ​void​ ​onConsentFormClosed​(ConsentStatus consentStatus, Boolean userPrefersAdFree) {
​// Consent form was closed.
}
})
.withPayOption()
.build();

consentForm.load();

The methods above prepare the EpomApps rendered consent form with the following options: 
withListener()

Registers a listener for the ​ConsentForm​. Each of the overridable methods in ​ConsentFormListener​ ​corresponds to 
an event in the lifecycle of the consent form. 
Method  Description 

onConsentFormLoaded The consent form successfully loaded. 

onConsentFormOpened The consent form was opened. 

onConsentFormClosed The consent form was closed. The parameters of the method provides the following 
information: 

● consentStatus​ is a C
​ onsentStatus ​value that describes the updated consent 
status of the user. 
● userPrefersAdFree​ has a value of true when the user chose to use a paid 
version of the app instead of viewing ads. 

onConsentFormError The consent form failed to load. The reason parameter provides a description of the 
error. 

withPayOption​()
Indicates that the consent form should show an ad-free app option. U
​ se a paid version of the app instead of viewing 
ads and collecting user data 
Once you have created a ​ConsentForm​ ​object, load the consent form by invoking the​ ​load()​ method of 
ConsentForm​, as shown below: 

consentForm.load(); 
 
To present the user with the consent form, call​ ​show()​ on an instance of C
​ onsentForm​, as demonstrated below: 
consentForm.show(); 
After the user selects an option and closes the form, the EpomApps consent SDK saves the user's choice and fires 
the ​onConsentFormClosed​ ​event. 

8.4 Storing Publisher-Managed Consent 


Upon getting consent, record the C
​ onsentStatus​ a
​ nd L
​ ocationStatus​ c​ orresponding to the user's response using 
the ​setConsentStatus(ConsentStatus consentStatus)​ and ​setLocationStatus(LocationStatus status) 
methods of ​the C
​ onsentInformationManager​ ​class: 
ConsentInformationManager consentInformationManager = ConsentInformationManager.getInstance(context);
consentInformationManager.setConsentStatus(ConsentStatus consentStatus);
consentInformationManager.setLocationStatus(LocationStatus status);

8.5 Change or Revoke Consent 

NOTE:​ I​ t is important that the user is able to change or revoke the consent they have provided at any time. 

To allow users to update their consent, simply repeat the steps outlined in the Collect consent section when the 
user chooses to update their consent status. 

 
 
   
9. Changelog 
Version 4.3.0   
● Updated ​Vungle to 6.3.24 
● Added support for application networks 
● Changed documentation 
● Bug fix 
Bug fix 
Version 4.2.1   
● Changed documentation 
● Added test key for Rewarded Video 
● Fixed Sample Application 
● Bug fix 
Version 4.2.0   
● Fixed smart banner for landscape mode
● Updated networks
1. Adcolony 3.3.7
2. Admob 17.1.2
3. Applovin 9.1.3
4. Appnext 2.4.4.472
5. Facebook 5.1.0
6. Chartboost 11.2.0
7. Inmobi 7.2.1
8. Inlocomedia 4.3.10
9. Mintegral 9.4.0
10. Mopub 5.4.1
11. Mytarget 5.4.1
12. StartApp 3.9.0
13. Tapjoy 12.2.0
14. Tappx 3.1.3
15. UnityAds 3.0.0
● Added new network Mobfox-3.6.4
● Updatedc gdpr sdk
● Changed version of play services:
○ ads 17.1.2
○ basement 16.1.0
○ location 16.0.0
○ plus 16.0.0
● upgraded version:
○ cmpileSdkVersion 28
○ buildToolsVersion '28.0.3'

Version 4.1.0 
 
● Native Ads 
➔ Changed ​AdClientNativeAdRenderer​ constructor signature from 
AdClientNativeAdRenderer(binder)​ t​ o A​ dClientNativeAdRenderer(context, binder)
➔ Changed initialization of ​AdClientNative​ instance: 
from: 
AdClientNativeAd adClientNativeAd = new AdClientNativeAd(context);
adClientNativeAd.setConfiguration(context, configuration);
adClientNativeAd.setRenderer(renderer);
 
  to: 
AdClientNativeAd adClientNativeAd = new AdClientNativeAd(context, configuration,
renderer);
 
➔ Changed ​AdClientNative​ methods ​load()​ and r ​ esume()​ signature (removed Context parameter) 
➔ Updated ad view rendering: 
from: 
View nativeAdView = adClientNativeAd.getView(context);
adClientNativeAd.renderView(nativeAdView);
adClientNativeAd.prepareView(nativeAdView);
 
  to: 
  View nativeAdView = adClientNativeAd.getView(context);
adClientNativeAd.renderView(nativeAdView);
adClientNativeAd.registerImpressionsAndClicks(nativeAdView);
 
➔ AdClientMediaView​ moved to c ​ om.adclient.android.sdk.nativeads.view​ package. 
➔ Created ​AdClientIconView​ class for showing icon & privacy icon assets instead of ​ImageView​. 
➔ Removed ​AdClientNativeAdBinder.ViewType.MAIN_IMAGE_VIEW​ (use 
AdClientNativeAdBinder.ViewType.MEDIA_VIEW​) 
➔ Renamed A ​ dClientNativeAdBinder.ViewType.ICON_IMAGE_VIEW​ to 
AdClientNativeAdBinder.ViewType.ICON_VIEW
➔ Renamed A ​ dClientNativeAdBinder.ViewType.PRIVACY_ICON_IMAGE_VIEW​ to 
AdClientNativeAdBinder.ViewType.PRIVACY_ICON_VIEW
➔ Improved ads rendering mechanism 
➔ Improved impressions and clicks handling 
● SmartBanner ads 
➔ Improved ads rendering mechanism 
➔ Improved impressions and clicks handling 
➔ Changed ​SmartBannerAdView​ l ​ oad()​ and ​resume()​ methods signature of (removed Context 
parameter) 
● Bug fixes. 

You might also like