I am trying to add admob ads to my app by whenever i try the ads do not show but when i use the test ads it shows. I have also cheked my admob account it has been approved for displaying ads
I have tried using the admob test ads and it shows perfectly
Here is an example of the banner ad
mAdView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
I expect it to show my ads but it shows only the test ads whenever I replace my ad unit with the test ad unit.
Try to confirm that you have used valid banner ad id, If you still not getting real ad wait sometimes and test in another device. Hope it will work
-----------:Add custom layout:--------------
<!--Admob Banner Ad-->
<RelativeLayout
android:id="#+id/rlAdViewBannerAdmob"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
public AdView ad;
AdRequest adRequest;
//init Ad
ad =new AdView(context);
ad.setAdSize(AdSize.SMART_BANNER);
ad.setAdUnitId(adUnitId);
//Load ad
adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("14C739553C9657EB85559903949D428B") //add test Ids
.build();
//load ad
ad.loadAd(adRequest);
rlAdViewBannerAdmob.addView(ad); // add loaded ad in customview
//do not forget to add *YOUR_ADMOB_APP_ID* in manifest
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR_ADMOB_APP_ID"/>
</application>
</manifest>
Related
Initially, my application was showing ads but recently I have updated my application on play store after which it is not showing banner ads most of the times but Interstitial ads are being shown.
After checking the logcat it shows "Ad failed to load : 3" which normally occurs initially when you release your apps/ads initially.
Below is the code:
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
<com.google.android.gms.ads.AdView
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="#string/first_banner"></com.google.android.gms.ads.AdView>
The ad request was successful, but no ad was returned due to lack of ad inventory.
There is nothing wrong with your code , the issue is admob doesnt always have Ad to return for your request possible reasons could be
-you have just registered your publisher id as it takes some time to start serving ads
-you have filtered some ads
Kindly refer this doc: https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#ERROR_CODE_NO_FILL
This is My Code:
AdView mAdView;
MobileAds.initialize(this, "ca-app-pub-9233630887794553~4351962429");
// Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
// values/strings.xml.
mAdView = (AdView) findViewById(R.id.ad_view);
mAdView.setAdUnitId(getString(R.string.banner_ad_unit_id));
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
Check the 2 answers from this link: admob only sends test ad not real ads
Publish your app and live ads will automatically come.
I am integrating admob in my application, using this tutorial. In debug mode, the Admob test banner ad is showing as expected. However, upon removing .addTestDevice("XXXXXXXXXXXXX") and building a signed APK, the real ad doesn't display. Instead the log displays the following:
07-07 16:10:23.743: I/Ads(20143): Starting ad request.
07-07 16:10:23.743: I/Ads(20143): Use AdRequest.Builder.addTestDevice("B2D638A0Bxxx024D83BE163E0E") to get test ads on this device.
Java Code:
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("B2D638A0BEEXXX4024D83BE163E0E")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
XML layout:
<com.google.android.gms.ads.AdView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:id="#+id/adView"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-96XXXXXXXX83/25383XX455" />
Interstitial ads are also integrated into this app and they're displaying perfectly both in debug- and production mode. Why are banners not displaying in production mode?
Found The Solution:
You must create separate ids for banner and Interstitial.While creating an ad-unit a small tab will be opened,if you select banner then an id representing a banner will be created and same goes for Interstitial.I was using Interstitial ID while creating the banner and as a result banner containing Real ads was not showing up.
I am trying to implement a banner advert in my Android application. I have used Gradle to download the dependencies, etc.
In my activity where I want the advert to be displayed I have:
<com.google.android.gms.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_mob_id" />
And ad_mob_id is
ca-app-pub-3940256099942544/6300978111
Which is for test ads, I took that from https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start#step_1_modify_the_main_activity_layout
However when I run the activity nothing is displayed and there are no errors/warnings generated.
Am I missing another step?
AdView mAdView = (AdView) getView().findViewById(R.id.adView); // locate the id the banner view
// if you do not use fragments and you are using it directing the remove the getView();
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest); // load it..that's all and you will see logs on it
i took it from the link you posted, it has all you need.
I want to track clicks on an AdMob banners with Google Analytics, but a problem occurs and I don't understand why.
Currently, my AdMob banner is implemented like this:
Layout:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="YOUR_AD_UNIT_ID"
ads:adSize="BANNER"/>
Java : AdView adView = (AdView)this.findViewById(R.id.adView);
However, the Google demonstration project which shows how to add an AdListener (project available here) does not specify anything in the layout and use the following code to add the banner:
LinearLayout layout = (LinearLayout) findViewById(R.id.leLinearLayoutDeMonChoix);
layout.addView(adView);
But if the implementation described at the beginning is used, the AdListener does not detect any event anymore. Why?
You can find this defective implementation in the following demonstration project: https://drive.google.com/file/d/0B8rE1pbtzNJ1UXg5QllubEFidGc/edit?usp=sharing
I thank you in advance for your time and help.
In the provided implementation you are doing the following:
// Create an ad.
adView = new AdView(this);
// Set the AdListener.
adView.setAdListener(new AdListener() {
/** stuff **/
}
AdView adView = (AdView)this.findViewById(R.id.adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
There is two instances of AdView, and this is your problem.
first one created from inflating your main.xml layout by setContentView(),
second one when you wrote adView = new AdView(this);
You set your listener on the second one, but only the first one is displayed.
It cannot work. :)
Choose one method (create it from layout) or the other (create it from code), but don't mix them up.
If you want to create your ad from layout, do the following:
// Retreive the adView.
AdView adView = (AdView)this.findViewById(R.id.adView);
// Set the AdListener.
adView.setAdListener(new AdListener() {
/** stuff **/
}
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);