Using Native Ads outside Mopub Adapter

android

#1

Hi!

I want to show a single native ad without using MoPub adapter.
I’m following this guide : https://github.com/mopub/mopub-android-sdk/wiki/Manual-Integration-of-Native-Ads

I’m making a request with moPubNative.makeRequest();
and I’m receiving an ad because onNativeLoad method is called.

But nothing is showing my view is still empty. I’m probably missing something. I think this is related to the “Rendering Native Ads” of the guide (https://github.com/mopub/mopub-android-sdk/wiki/Manual-Integration-of-Native-Ads#rendering-native-ads)

The rendering is related to an Adapter, but in my case I’m not using any adapter…

What do I need to do once I receive a Native Ad through the onNativeLoad callback?


Native ad without adapter privacy click reset
#2

Hi @Guitoun3,

Thanks for reaching out! Is there a reason for not using the adapter? Native is a little more sophisticated than other ad formats, so we would like to understand the use case first.

Thanks!


#3

Hi!

Actually I found a solution. I was missing some part.
I’m using Native Ad outisde adapter because I wanted to show native ad in my ViewPager.


#4

Hi, how did you fix ? I am facing the same issue


#5

Here is my code :

public void init() {
	MoPubNative mMoPubNative = new MoPubNative(activity, activity.getString(R.string.mopub_native_popup), this);

	ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_popup)
	                .mainImageId(R.id.native_main_image)
	                .iconImageId(R.id.native_icon_image)
	                .titleId(R.id.native_title)
	                .textId(R.id.native_text)
	                .callToActionId(R.id.native_cta)
	                .build();

	MoPubStaticNativeAdRenderer adRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
	mMoPubNative.registerAdRenderer(adRenderer);

	mMoPubNative.makeRequest();
}

@Override
public void onNativeLoad(NativeAd nativeAd) {
    View mView = nativeAd.createAdView(getActivity(), null);
    nativeAd.renderAdView(mView);
    nativeAd.prepare(mView);
}

@Override
public void onNativeFail(NativeErrorCode errorCode) {
    
}

Hope it will help :slight_smile:


#6

it does indeed. Thanks for sharing it.


#7

Hello,
I had followed this method for that I want to show native ad in my ViewPager, too.
I want to “cache” the ad.
What I did is to save the nativeAd in an Array as a static variable.
But there comes some problem.
When the cache ad is loaded, I still do createAdView, renderAdView and prepare.
But I found that sometimes when two ad is the same between the viewPager.
One of the ad can’t click.
The most weird thing is that it won’t happen when mediate the marketplace ad( as direct sales) but happen on facebook and flurry mediation.

Hope someone can help thanks.