I'm trying to implement native ads in my android application. But I want to do it using admob only. I searched a lot for solution but could not find exact one to do so.
I know it is possible using MoPub.
What I wanted to do is this:
Show ads inside list item which means one of the ListView/RecyclerView item can be one ad like below image.
I found some links and references but that doesn't explain proper implementation of the native ads.
Link 1 : Native ads overview
Link 2 : DFP Android Guides > Targeting
Link 3 : DFP Quick Start Guide
If it is not possible to do it using admob, MoPub is best solution for me right now.
Any help and guidance would be helpful. thanks.
Recently I stucked with the same question. Then I decided to post my solution for that to admobadapter. Hope it will help you.
The basic usage could look like:
ListView lvMessages;
AdmobAdapterWrapper adapterWrapper;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initListViewItems();
}
/**
* Inits an adapter with items, wrapping your adapter with a {#link AdmobAdapterWrapper} and setting the listview to this wrapper
* FIRST OF ALL Please notice that the following code will work on a real devices but emulator!
*/
private void initListViewItems() {
lvMessages = (ListView) findViewById(R.id.lvMessages);
//creating your adapter, it could be a custom adapter as well
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1);
adapterWrapper = new AdmobAdapterWrapper(this);
adapterWrapper.setAdapter(adapter); //wrapping your adapter with a AdmobAdapterWrapper.
//here you can use the following string to set your custom layouts for a different types of native ads
//adapterWrapper.setInstallAdsLayoutId(R.layout.your_installad_layout);
//adapterWrapper.setcontentAdsLayoutId(R.layout.your_installad_layout);
//Sets the max count of ad blocks per dataset, by default it equals to 3 (according to the Admob's policies and rules)
adapterWrapper.setLimitOfAds(3);
//Sets the number of your data items between ad blocks, by default it equals to 10.
//You should set it according to the Admob's policies and rules which says not to
//display more than one ad block at the visible part of the screen,
// so you should choose this parameter carefully and according to your item's height and screen resolution of a target devices
adapterWrapper.setNoOfDataBetweenAds(10);
//It's a test admob ID. Please replace it with a real one only when you will be ready to deploy your product to the Release!
//Otherwise your Admob account could be banned
//String admobUnitId = getResources().getString(R.string.banner_admob_unit_id);
//adapterWrapper.setAdmobReleaseUnitId(admobUnitId);
lvMessages.setAdapter(adapterWrapper); // setting an AdmobAdapterWrapper to a ListView
//preparing the collection of data
final String sItem = "item #";
ArrayList<String> lst = new ArrayList<String>(100);
for(int i=1;i<=100;i++)
lst.add(sItem.concat(Integer.toString(i)));
//adding a collection of data to your adapter and rising the data set changed event
adapter.addAll(lst);
adapter.notifyDataSetChanged();
}
And the result will look like the following
Try using some other ad networking where it provides different types of native ads. Developers can customize the ads where to place and use it. For eg: if you need to place ads at second cell every 15 row, you can use like this.
Avocarrot provides that.
AvocarrotInstream myAd = new AvocarrotInstream(<yourListAdapter>);
myAd.initWithKey( "<your API Key>" );
myAd.setSandbox(true);
myAd.setLogger(true ,"ALL");
// Populate with In-Stream ads
myAd.loadAdForPlacement(this, "<your Placement Name>" );
// Bind the adapter to your list view component
<yourListView>.setAdapter(myAd);// here you are integrating ads to listview
myAd.setFrequency(2,15); // every 15 cells starting from the 2nd cell.
Here is Documentation it provides List ads and Feed ads.
Native ads are included in Google Play Services along with the rest of DFP/AdMob advertising. Make sure you have the following listed as dependencies in your build.gradle (note that 7.5.0 is the highest version as of this posting).
compile "com.google.android.gms:play-services-base:7.5.0"
compile "com.google.android.gms:play-services-ads:7.5.0"
Then you can display native ads
AdLoader adLoader = new AdLoader.Builder(context, "/6499/example/native")
.forAppInstallAd(new OnAppInstallAdLoadedListener() {
#Override
public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {
// Show the app install ad.
}
})
.forContentAd(new OnContentAdLoadedListener() {
#Override
public void onContentAdLoaded(NativeContentAd contentAd) {
// Show the content ad.
}
})
.withAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
// Handle the failure by logging, altering the UI, etc.
}
})
.withNativeAdOptions(new NativeAdOptions.Builder()
// Methods in the NativeAdOptions.Builder class can be
// used here to specify individual options settings.
.build())
.build();
Click here for complete documentation.
As an addition to this thread, you can now implement NativeAds for Admob very easily by following the guide provided by Google using NativeExpressAdView .
For more information, check the google documentation :
https://firebase.google.com/docs/admob/android/native-express?hl=en
Add this code to your Listview Adapter
builder.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
#Override
public void onAppInstallAdLoaded(NativeAppInstallAd ad) {
FrameLayout frameLayout =
(FrameLayout) findViewById(R.id.fl_adplaceholder);
NativeAppInstallAdView adView = (NativeAppInstallAdView) getLayoutInflater()
.inflate(R.layout.ad_app_install, null);
populateAppInstallAdView(ad, adView);
frameLayout.removeAllViews();
frameLayout.addView(adView);
}
});
AdLoader adLoader = builder.withAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(MainActivity.this, "Failed to load native ad: "
+ errorCode, Toast.LENGTH_SHORT).show();
}
}).build();
adLoader.loadAd(new AdRequest.Builder().build());
Make some changes for listview Adapter and you will get populateAppInstallAdView() method from below link
Everything is covered in this example please go through this
https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob
Adding to the mix, Tooleap Ads SDK provides a simple way to implement Admob's native ads.
Instead of requiring you to use the traditional listView adapter and showing the ad inside you content, they are showing admob native ads as a small floating bubble. When pressing on it you can see the full native ad.
Here is an example of using their SDK inside your activity class:
BubbleImageAd = new BubbleImageAd(this);
bubbleImageAd.setAdUnitId("YOUR_AD_UNIT_ID");
bubbleImageAd.loadAndShowAd(this);
You can check them out here.
This is working for me:
Copy Native template in project library.
in Build.gradle(Module:Appname) - add this:
implementation project(':nativetemplates')
implementation 'com.google.android.gms:play-services-ads:20.4.0'
in Setting.gradle(Appname) - add this:
include ':nativetemplates'
in Mainfest - update as earlier.
Before Application:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
add this Permission:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
In Layout file add this:
<com.google.android.ads.nativetemplates.TemplateView
android:id="#+id/my_template"
app:gnt_template_type="#layout/gnt_medium_template_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.google.android.ads.nativetemplates.TemplateView>
In program file:
MobileAds.initialize(this)
//build ad
val adLoader = AdLoader.Builder(this,"ca-app-pub-3940256099942544/2247696110")
.forNativeAd {
val style = NativeTemplateStyle.Builder().withMainBackgroundColor(ColorDrawable(Color.WHITE))
.build()
val template = findViewById<TemplateView>(R.id.my_template)
template.setStyles(style)
template.setNativeAd(it)
}.build()
//show ad
adLoader.loadAd(AdRequest.Builder().build())
If still not loading, Check with your admod credentials.
Well, this thread is probably outdated. But starting May 2015, and as of now, AdMob does support native ads (still in beta though).
https://support.google.com/admob/answer/6239795
Also it's available only to a limited number of developers as of its beta stage.
Admob in your android these are the codes needed.
<com.google.android.gms.ads.AdView
android:layout_alignParentBottom="true"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-4549020480017205/6066702579"
/>
//In your java class file
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
⟩⟩ In project structure, navigate to activity_main.xml and paste the following code in your layout.
<com.google.android.gms.ads.NativeExpressAdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="320x300"
ads:adUnitId="#string/ad_unit_id">
</com.google.android.gms.ads.NativeExpressAdView>
and in the same file i.e activity_main.xml add below lines of code in the header part
xmlns:ads="http://schemas.android.com/apk/res-auto"
⟩⟩ Now open MainActivity.java and add below lines of code in public class
private static String LOG_TAG = "EXAMPLE";
NativeExpressAdView mAdView;
VideoController mVideoController;
⟩⟩ Then under MainActivity.java and add below lines of code in onCreate() method.
// Locate the NativeExpressAdView.
mAdView = (NativeExpressAdView) findViewById(R.id.adView);
// Set its video options.
mAdView.setVideoOptions(new VideoOptions.Builder()
.setStartMuted(true)
.build());
// The VideoController can be used to get lifecycle events and info about an ad's video
// asset. One will always be returned by getVideoController, even if the ad has no video
// asset.
mVideoController = mAdView.getVideoController();
mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
#Override
public void onVideoEnd() {
Log.d(LOG_TAG, "Video playback is finished.");
super.onVideoEnd();
}
});
// Set an AdListener for the AdView, so the Activity can take action when an ad has finished
// loading.
mAdView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (mVideoController.hasVideoContent()) {
Log.d(LOG_TAG, "Received an ad that contains a video asset.");
} else {
Log.d(LOG_TAG, "Received an ad that does not contain a video asset.");
}
}
});
mAdView.loadAd(new AdRequest.Builder().build());
⟩⟩ Now open string.xml file in values folder and paste the below line of code.
<string name="ad_unit_id">ca-app-pub-39402560999xxxxx/21772xxxxx</string>
⟩⟩ Then open the Manifest file and add Internet permission to it.
<uses-permission android:name="android.permission.INTERNET" />
THE RESOURCE : How to insert AdMob Native Ad in your Android App
It is restricted to selected publishers at the moment. You'll need to contact a Google account manager in your region for implementation.
Yes it is possible you can use below code in xml file
<com.google.android.gms.ads.NativeExpressAdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="320x300"
ads:adUnitId="#string/ad_unit_id">
mAdView.setVideoOptions(new VideoOptions.Builder()
.setStartMuted(true)
.build());
mVideoController = mAdView.getVideoController();
mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
#Override
public void onVideoEnd() {
Log.d(LOG_TAG, "Video playback is finished.");
super.onVideoEnd();
}
});
mAdView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (mVideoController.hasVideoContent()) {
Log.d(LOG_TAG, "Received an ad that contains a video asset.");
} else {
Log.d(LOG_TAG, "Received an ad that does not contain a video asset.");
}
}
});
mAdView.loadAd(new AdRequest.Builder().build());
To add Native Templates in our app we have to follow some basic steps:
1-First, we have to download the Native Templates, so got to developers.google
2-Then click on the Download Native Templates, now you will be directed to Github
3-Then download the zip file from GitHub and extract the zip file to any folder and remember the location of the folder, we will use it later
4-Now go inside Android studio and click on File->New->Import Module, Now you will see a new window (Import-Module from Source) Now click on the Browse icon and select the nativetemplates folder and click on finish and wait for Gradle build to finish.
5-Now open the Gradle Scripts->build.gradle (Module: app) section and import the nativetemplates project and click the "sync Now" show at the top as shown below:
//adding native templates
implementation project(':nativetemplates')
https://www.studytonight.com/post/how-to-add-admob-native-ad-in-android-app#
Related
I'm implementing google native ads on android.Most of the code I copy/pasted from this example
The only difference is I request bunch of ads instead of one ad.Here is load function:
public void loadAds(String unitId,int count) {
if (nativeAds.size()>0) {
for(UnifiedNativeAd ad: nativeAds)
ad.destroy();
}
nativeAds =new ArrayList();
//load
AdLoader.Builder builder = new AdLoader.Builder(context, unitId);
builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
// OnUnifiedNativeAdLoadedListener implementation.
#Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd nativeAd) {
// You must call destroy on old ads when you are done with them,
// otherwise you will have a memory leak.
//nativeAd = unifiedNativeAd;
int numAds =nativeAds.size();
int insertTo=numAds==0? firstAdPosition : firstAdPosition +numAds*(AdStep +1);
CategoryData item = new CategoryData();
item.type = ItemData.TYPE_CATEGORIES_NATIVE_AD;
if (insertTo<data.size())
data.add(insertTo, item);
item = new CategoryData();
item.type = ItemData.TYPE_CATEGORIES_SEPARATOR;
if (insertTo<data.size())
data.add(insertTo+1, item);
nativeAds.add(nativeAd);
Log.d("nativead","got ad body "+nativeAds.size()+":"+nativeAd.getBody());
notifyItemRangeInserted(insertTo,2);
}
});
VideoOptions videoOptions = new VideoOptions.Builder()
.setStartMuted(true)
.build();
NativeAdOptions adOptions = new NativeAdOptions.Builder()
.setVideoOptions(videoOptions)
.build();
builder.withNativeAdOptions(adOptions);
AdLoader adLoader = builder.withAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
Log.d("nativead","error code " +errorCode);
/*
Toast.makeText(context, "Failed to load native ad: "
+ errorCode, Toast.LENGTH_SHORT).show();
*/
}
}).build();
AdRequest adRequest;
// get unpersonalized ads if needed
if(AppModel.getAppData().gdpr.eea && AppModel.getAppData().gdpr.consentStatus!= ConsentStatus.PERSONALIZED) {
Bundle extras = new Bundle();
extras.putString("npa", "1");
adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,extras).build();
} else {
adRequest = new AdRequest.Builder().build();
}
adLoader.loadAds(adRequest,count);
//adLoader.loadAd(adRequest);
}
First time it loads ok, but if I restart the app it throws a bunch of errors:
I/Ads: Received log message: The ad request returned a no fill for the particular slot. The error log below that says 'Malformed native JSON response' is a benign warning that will be removed in a future SDK release.
Also error code 0 is passed into onAdFailedToLoad.If I clear app's data banners are loaded again but again only for single run
As you mentioned, in the comment above, you're testing it on real ad units (which is quite dangerous as you might get blocked for that).
You're getting NO_FILL, which means there is no inventory left to serve in the AdMob backend.
You can find out more about this issue (not an issue, we can call it a "thing") here.
To get proper results, always test with test ads, so that you get maximum fill rate for the ads while testing.
You'll find the ad unit ID's for test ads on this page.
And, if you still get NO_FILL error a lot in production, try using mediation to get ads from multiple ad sources. You'll never get 100% fill rate for your ads, though, so make sure you code accordingly to handle the NO_FILL.
Also, one more reminder, do not use live ads to test the app, you might get blocked by Admob/Google for doing that.
As the Documentation of Mopub say's here ,integrated the Native ads and followed by Native Video ads.
After integrating the code the ad request response is calling the callback method onNativeFail()
with some of the response
Below code is related to the workflow and logcat message
public class MainActivity extends Activity {
private MoPubView moPubView;
//private MoPubInterstitial mInterstitial;
private MoPubNative moPubNative;
private MoPubNativeNetworkListener moPubNativeNetworkListener;
private NativeAd.MoPubNativeEventListener moPubNativeEventListener;
AdapterHelper adapterHelper;
private NativeFullScreenVideoView nativeFullScreenVideoView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
moPubNativeNetworkListener = new MoPubNativeNetworkListener() {
#Override
public void onNativeLoad(NativeAd nativeAd) {
Log.d("MoPub", "Native ad has loaded.");
}
#Override
public void onNativeFail(NativeErrorCode errorCode) {
Log.d("MoPub", "Native ad failed to load with error: " + errorCode.toString());
}
};
moPubNativeEventListener = new NativeAd.MoPubNativeEventListener() {
#Override
public void onImpression(View view) {
Log.d("MoPub", "Native ad recorded an impression.");
// Impress is recorded - do what is needed AFTER the ad is visibly shown here.
}
#Override
public void onClick(View view) {
Log.d("MoPub", "Native ad recorded a click.");
// Click tracking.
}
};
moPubNative = new MoPubNative(this, "02a2d288d2674ad09f3241d46a44356e ", moPubNativeNetworkListener);
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_list_item)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build();
MediaViewBinder mediaViewBinder = new MediaViewBinder.Builder(R.layout.native_video_ad_layout)
.mediaLayoutId(R.id.native_ad_video_view)
.iconImageId(R.id.native_ad_icon_image)
.titleId(R.id.native_ad_title)
.textId(R.id.native_ad_text)
.build();
MoPubVideoNativeAdRenderer moPubVideoNativeAdRenderer = new MoPubVideoNativeAdRenderer(mediaViewBinder);
moPubNative.registerAdRenderer(moPubVideoNativeAdRenderer);
MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
EnumSet<RequestParameters.NativeAdAsset> desiredAssets = EnumSet.of(
RequestParameters.NativeAdAsset.TITLE,
RequestParameters.NativeAdAsset.TEXT,
RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT,
RequestParameters.NativeAdAsset.MAIN_IMAGE,
RequestParameters.NativeAdAsset.ICON_IMAGE,
RequestParameters.NativeAdAsset.STAR_RATING
);
RequestParameters mRequestParameters = new RequestParameters.Builder()
.desiredAssets(desiredAssets)
.build();
moPubNative.makeRequest();
}
}
After running this code, the ad is not getting loaded and the response of my code is below
06-06 17:01:41.797 24421-24421/? I/Ads: Webview loading for native ads.
06-06 17:01:41.911 24421-24421/? I/Ads: Javascript has loaded for native ads.
06-06 17:02:18.623 24421-24421/? I/Ads: Webview loading for native ads.
06-06 17:02:18.954 24421-24421/? I/Ads: Javascript has loaded for native ads.
06-06 17:02:51.796 13278-13278/com.fabgrad.students.android D/MoPub: Native ad request failed.
com.mopub.network.MoPubNetworkError: No ads found for ad unit.
at com.mopub.network.AdRequest.parseNetworkResponse(AdRequest.java:180)
at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
06-06 17:02:51.800 13278-13278/com.fabgrad.students.android D/MoPub: Native ad failed to load with error: Server returned empty response.
As per their blog, No ads found will come for following scenarios:
These errors indicate that there was no fill for your ad unit.
No ad network will have fill 100% of the time, so seeing this log is normal. New apps and apps with very low volume tend to experience lower fill rates. Contact your ad network representative if you have any concerns related to a particular network’s fill.
If you are consistently seeing no fill, review your ad network placement details in the Networks tab of the MoPub UI, as well as your settings in the Network’s UI.
You won’t be able to show ads from Certified Ad Networks if you forgot to include the network SDK or adapter files. The Couldn't locate or instantiate custom event and Unable to find Native Network or Custom Event adapter log messages are indicators that the network SDK or adapter file is missing, renamed, or in the wrong location.
Review our Integrating Third-Party Ad Networks documentation to resolve this.
Link for reference.
i try everything in stackoverflow but ads not show. banner and other working but native not working please help me.
inal NativeExpressAdView mAdView2 = (NativeExpressAdView) findViewById(R.id.adView2);
// Set its video options.
mAdView2.setVideoOptions(new VideoOptions.Builder()
.setStartMuted(true)
.build());
// The VideoController can be used to get lifecycle events and info about an ad's video
// asset. One will always be returned by getVideoController, even if the ad has no video
// asset.
mVideoController = mAdView2.getVideoController();
mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
#Override
public void onVideoEnd() {
Log.d(LOG_TAG, "Video playback is finished.");
super.onVideoEnd();
}
});
// Set an AdListener for the AdView, so the Activity can take action when an ad has finished
// loading.
mAdView2.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
mAdView2.setVisibility(View.VISIBLE);
if (mVideoController.hasVideoContent()) {
Log.d(LOG_TAG, "Received an ad that contains a video asset.");
} else {
Log.d(LOG_TAG, "Received an ad that does not contain a video asset.");
}
}
});
mAdView2.loadAd(adRequest);
this activity code
this is xml code . please help me.
<com.google.android.gms.ads.NativeExpressAdView
android:id="#+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-000000"
ads:adSize="300x150"
android:visibility="gone"
>
</com.google.android.gms.ads.NativeExpressAdView>
Logcat report
You just need to wait a little. Your ad id is newly created so it will take some time to fetch ads from google servers.
It also happened to me that error "fail to load ad 0" but there is no problem just wait for sometimes like an hour or 2 or even 5 hours just wait you will get the ads.
I am using the following view in my activity xml.
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-6844894412719021~8904567900">
</com.google.android.gms.ads.AdView>
Your adUnitId seems to be incorrect. Did you get it via email?
You should be using following app id (replace ~ with /)
ads:adUnitId="ca-app-pub-6844894412719021/8904567900">
Try to add to your xml:
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
and to gradle:
compile 'com.google.android.gms:play-services-ads:9.8.0'
It looks like you are using app_id instead of banner_id.
<string name="app_id">ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx</string>
<string name="banner_id">ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx</string>
these two values are different from each other.
Check if you have latest versions of adMob and GooglePlayServices lib.
When you try to show banner inside of svg images then care about it are you using smart banner or banner it may effect, sometimes you implement the code right but when you try to show toast in ad loaded like this.
adView2.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
Toast.makeText(App_Mainpage.this, "add is loaded", Toast.LENGTH_SHORT).show();
adView2.setVisibility(View.VISIBLE);
}
#Override
public void onAdFailedToLoad(int errorCode) {
}
#Override
public void onAdOpened() {
}
#Override
public void onAdLeftApplication() {
}
#Override
public void onAdClosed() {
}
});
AdRequest adRequest = new AdRequest.Builder().build();
adView2.loadAd(adRequest);
if it shows you in toast the ad is loaded but not showing when you testing, then actually you are implementing Smart_banner that takes large space to show, so use Banner Just it will show then, i solve it by change this thing.
then i changed to smart banner .
I'm having issues with ADs in my Android App.
Sometimes the AD is not shown, probably depending on the DPI or Size of the screen's device.
In my code, I implemented a check to set View.GONE in case the AD fails to load, but despite that on some devices I still have blank spaces where it's supposed to be the AD
For example, here one of my ADs
if(holder.nativeExpressAdView != null) {
AdRequest request = new AdRequest.Builder()
.build();
holder.nativeExpressAdView.loadAd(request);
Utilities.setAdListenerNative(holder.nativeExpressAdView);
}
//ADs listener to remove view if it fails load
//NATIVE ADS
public static void setAdListenerNative(final NativeExpressAdView nativeExpressAdView) {
nativeExpressAdView.setAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
nativeExpressAdView.setVisibility(View.GONE);
}
});
}
First show me your log
Second Dont use "Gone" because this will change the position of the adView if you are using other sizes of Android scale you will see that.
Third use a debugger.
Use "invisible"