Native Ad
1. Basic requirements
Add ADX Android SDK to your project.
Use the Ad Unit ID issued for Native Ad.
Before requesting an ad, SDK initialization must be done first.
SDK initialization should be called only once when the app launches and ad requests should be made after SDK initialization is complete.
2. Layout setup
For Native Ads, you must create the layout to be used for the ad yourself. The required components are as follows.
Title :
TextView
Main Text :
TextView
Call-To-Action :
Button
Icon Image :
ImageView
Main Image :
FrameLayout
Privacy Icon :
FrameLayout
Ad Tag :
TextView or ImageView
Ensure that these elements are included and properly configured, and that no layer covers the ad content. Also, avoid modifying any part of the ad content, such as changing text, images, or touch actions.
Refer to the sample source layout_adx_native_ad.xml for reference.
3. Implementation
Native Ads can be loaded using any of the following three methods.
Case 1: Using a single ad view
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdxNativeAdFactory.init(this);
// for Native Ad
AdxNativeAdFactory.setAdxViewBinder("<NATIVE_AD_UNIT_ID>"),
new AdxViewBinder.Builder(R.layout.layout_media_native_ad)
.mediaViewContainerId(R.id.mediaContainerId)
.iconImageId(R.id.adIconId)
.titleId(R.id.titleId)
.adChoiceContainerId(R.id.adChoicesContainerId)
.callToActionId(R.id.callToActionId)
.build());
AdxNativeAdFactory.preloadAd("<NATIVE_AD_UNIT_ID>");
}
Activity (or Fragment)
private View mAdView;
private com.adxcorp.ads.nativeads.NativeAd mNativeAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_native_ad_factory);
AdxNativeAdFactory.addListener(mListener);
AdxNativeAdFactory.loadAd("<NATIVE_AD_UNIT_ID>");
}
@Override
protected void onDestroy() {
AdxNativeAdFactory.removeListener(mListener);
if(mNativeAd != null) {
mNativeAd.destroy();
mNativeAd = null;
}
super.onDestroy();
}
private final AdxNativeAdFactory.NativeAdListener mListener = new AdxNativeAdFactory.NativeAdListener() {
@Override
public void onSuccess(String s, com.adxcorp.ads.nativeads.NativeAd nativeAd) {
if ("<NATIVE_AD_UNIT_ID>".equals(s)) {
mNativeAd = nativeAd;
mAdView = AdxNativeAdFactory.getNativeAdView(
NativeAdFactoryActivity.this,
s,
mContentView,
new com.adxcorp.ads.nativeads.NativeAd.NativeEventListener() {
@Override
public void onImpression(View view) {
}
@Override
public void onClick(View view) {
}
});
mContentView.addView(mAdView);
}
}
@Override
public void onFailure(String s) {
}
};
Case 2: Using RecyclerView
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdxNativeAdFactory.init(this);
// for Native Ad
AdxNativeAdFactory.setAdxViewBinder("<NATIVE_AD_UNIT_ID>"),
new AdxViewBinder.Builder(R.layout.layout_media_native_ad)
.mediaViewContainerId(R.id.mediaContainerId)
.iconImageId(R.id.adIconId)
.titleId(R.id.titleId)
.adChoiceContainerId(R.id.adChoicesContainerId)
.callToActionId(R.id.callToActionId)
.build());
}
Acivity (or Fragment)
You must define fixed and repeating ad positions directly in the source code for the list.
private AdxRecyclerAdapter mRecyclerAdapter;
private RecyclerView mRecyclerView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_native_ad_recyclerview);
mRecyclerView = (RecyclerView) findViewById(R.id.native_recycler_view);
final RecyclerView.Adapter originalAdapter = new DemoRecyclerAdapter();
// Specify fixed and repeating ad positions
NativeAdPosition.ClientPosition clientPosition = new NativeAdPosition.ClientPosition();
clientPosition.addFixedPosition(2);
clientPosition.enableRepeatingPositions(5);
mRecyclerAdapter = AdxNativeAdFactory.getAdxRecyclerAdapter(this, originalAdapter, "<Insert_ADX_AdUnitId>", clientPosition);
mRecyclerView.setAdapter(mRecyclerAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerAdapter.loadAds("<NATIVE_AD_UNIT_ID>");
}
@Override
protected void onDestroy() {
super.onDestroy();
mRecyclerAdapter.destroy();
}
Case 3: Using Close Native Ad
After consulting the responsible manager, implement the following using the Ad Unit ID issued for Close Native Ad.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_wall);
AdxCloseAdFactory.init(this, "<NATIVE_AD_UNIT_ID>", "Exit Message");
AdxCloseAdFactory.preloadAd();
}
@Override
public void onBackPressed() {
AdxCloseAdFactory.showCloseAd(this, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
}
@Override
protected void onDestroy() {
AdxCloseAdFactory.destroy();
super.onDestroy();
}
4. Ad Revenue (OnPaidEvent)
You can receive the estimated ad revenue while an ad impression occurs.
Manually set values during mediation setup and actual values may be mixed, so it is recommended to treat this as an estimate.
The currency unit of eCPM is USD.
As shown in the example below, use
OnPaidEvent
to check the estimated eCPM value.You can link ad revenue data with your MMP. For details, please refer to the SDK integration guides below:
This feature is only supported for Native Ad.
private final AdxNativeAdFactory.NativeAdListener mListener = new AdxNativeAdFactory.NativeAdListener() {
@Override
public void onSuccess(String s, com.adxcorp.ads.nativeads.NativeAd nativeAd) {
if (mAdxUnitId.equals(s)) {
mNativeAd = nativeAd;
mNativeAd.setOnPaidEventListener(new OnPaidEventListener() {
@Override
public void onPaidEvent(double ecpm) {
/// Firebase Analytics Example
double revenue = ecpm / 1000;
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "AD(X)");
params.putString(FirebaseAnalytics.Param.AD_FORMAT, "NativeAd");
params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, "ADX Native Ad");
params.putDouble(FirebaseAnalytics.Param.VALUE, revenue);
params.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params);
/// AppsFlyer Example
double revenue = ecpm / 1000;
Map<String, String> customParams = new HashMap<>();
customParams.put(Scheme.AD_TYPE, "NativeAd");
customParams.put("ad_unit_name", "ADX Native Ad");
AppsFlyerAdRevenue.logAdRevenue(
"AD(X)",
MediationNetwork.customMediation,
Currency.getInstance(Locale.US),
revenue,
customParams
);
}
});
}
}
@Override
public void onFailure(String s) {
}
};
Last updated
Was this helpful?