AdMob banner ad not showing
Asked Answered
P

9

16

I am using admob in my app, it was working fine but suddenly it stopped showing ads at all. Bellow is my codes i used:

mainActivity.xml:

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

MainActivity.java

        AdView mAdView = (AdView) findViewById(R.id.adView);

        AdRequest adRequest = new AdRequest.Builder().build();

        mAdView.loadAd(adRequest);

AndroidManifest:

 <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="19" />

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

<meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />  

<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />

I followed all the instructions from adMob site as i said it was working few days ago.

Bellow are few line from logcat which may be related to my issue:

09-25 22:44:50.292: E/dalvikvm(18554): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza

09-25 22:45:07.209: E/Ads(18554): JS: Uncaught ReferenceError: renderAd is not defined (https://googleads.g.doubleclick.net/mads/gma:1)
09-25 22:45:07.209: E/Web Console(18554): Uncaught ReferenceError: renderAd is not defined:1
09-25 22:45:07.209: E/Ads(18554): JS: Uncaught ReferenceError: onLoad is not defined (https://googleads.g.doubleclick.net/mads/gma:1)
09-25 22:45:07.209: E/Web Console(18554): Uncaught ReferenceError: onLoad is not defined:1

I get bellow warning repeatedly and it appears more when i click the blank area where ad should be showing

09-25 22:46:10.911: W/PicturePileLayerContent(18554): Warning: painting PicturePile without content!

This is filtered logcat with "ads"

09-25 23:39:25.948: I/Ads(28874): Starting ad request.
09-25 23:39:25.948: I/Ads(28874): Use AdRequest.Builder.addTestDevice("8FCD71CAAE776558876AAA9BA964245A") to get test ads on this device.

09-25 23:39:26.919: I/Ads(22050): App index is not enabled
09-25 23:39:30.432: E/Ads(28874): JS: Uncaught ReferenceError: renderAd is not defined (https://googleads.g.doubleclick.net/mads/gma:1)
09-25 23:39:30.442: E/Ads(28874): JS: Uncaught ReferenceError: onLoad is not defined (https://googleads.g.doubleclick.net/mads/gma:1)
09-25 23:39:30.442: I/Ads(28874): Scheduling ad refresh 60000 milliseconds from now.
09-25 23:39:30.472: I/Ads(28874): Ad finished loading.

I have searched everywhere for the solution and also looked at some similar but non of them helped me.

Pending answered 25/9, 2015 at 17:19 Comment(1)
i get this error after adding builder().addTestDevice("******") 09-26 14:26:49.691: E/Ads(28853): JS: Uncaught ReferenceError: renderAd is not defined (https://googleads.g.doubleclick.net/mads/gma:1) 09-26 14:26:49.701: E/Ads(28853): JS: Uncaught ReferenceError: onLoad is not defined (https://googleads.g.doubleclick.net/mads/gma:1) Pending
P
9

This problem is solved by uninstalling the app manually and reinstalling again without making any changes!!

Pending answered 27/10, 2015 at 6:28 Comment(1)
It works! Your question was not about testing, right?Lurlinelusa
L
18

Use below lines of code

AdView mAdView = (AdView) findViewById(R.id.adView);

AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)        // All emulators
.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4")  // My Galaxy Nexus test phone
.build();


mAdView.loadAd(request );

instead of using this

AdRequest adRequest = new AdRequest.Builder().build();

because this line will be used when your application would be ready for publish on Google Play Store.

You can place your device's id in place of "AC98C820A50B4AD8A2106EDE96FB87D4". Code to get device id:

String android_id = Settings.Secure.getString(getContext().getContentResolver(),
            Settings.Secure.ANDROID_ID);

Please read these carefully:

https://developers.google.com/admob/android/targeting#test_ads

https://developers.google.com/admob/android/quick-start

See this

enter image description here

enter image description here

Lentamente answered 25/9, 2015 at 18:34 Comment(7)
i tried your code, it removed this lines from logcat ` 09-25 23:39:25.948: I/Ads(28874): Use AdRequest.Builder.addTestDevice("8FCD71F44FG4H6D7DAAA9BA964245A") to get test ads on this device` , but ad still not showing!!!Pending
Google has requested to not use that code (you have used previously) when your app is in development mode. May be your add id has been dismissed. Try some other email and create another add request.Lentamente
But I was using default adUnitId which was provided in instructions, I have not used the original adUnitId provide to me.Pending
I read the "getting started" guid again , it clearly says that the adUnitID given in example is testing purposes and it will retrive test ad, in last step it is mentioned that after loading ad with AdRequest.bhuilder().build(); I will start getting test ads. what i see in 2nd FAQ is How do I get test ads? The ad unit and samples that we provide return test ads. You can also request test ads by using AdRequest.Builder.addTestDevice.Pending
Listen integrating adds in android is only 30 minutes task.. I don't know what are you reading from these tutorial.Lentamente
Yes I know it is 30 min task and I setup admob very easily, it was successfully showing test ads, I dont know why it stopped showing ads now.Pending
Try with other email accountLentamente
P
9

This problem is solved by uninstalling the app manually and reinstalling again without making any changes!!

Pending answered 27/10, 2015 at 6:28 Comment(1)
It works! Your question was not about testing, right?Lurlinelusa
C
2

Check if you have latest versions of adMob and GooglePlayServices lib.

Contralto answered 25/9, 2015 at 18:4 Comment(1)
I just added Google play services which shows Rev. 26, i dont know about adMob version there is no instruction for this lib on official site.Pending
F
2

In my case the ad didnt show up until I gave enough room for it.

Before it was like

<LinearLayout
        android:orientation="vertical"
        android:background="@color/primary"
        android:layout_width="match_parent"
        android:layout_height="90dip">
           <ImageView
                android:onClick="goBack"
                android:clickable="true"
                android:src="@drawable/ic_arrow_back_white_48dp"
                android:layout_width="50dip"
                android:layout_height="50dip"/>
           <com.google.android.gms.ads.AdView
                android:layout_gravity="center_horizontal"
                android:id="@+id/adView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ads:adSize="BANNER"
                ads:adUnitId="@string/dwn_bnr_ad"/>

Here the adview is having height of wrap_content, so it adjusts itself to achieve its height, but its parent (LinearLayout) has a strict height of 90dip which doesnt allow the adView to take enough space to display ads.

So what I did was just changed the height of the LinearLayout to wrap_content then things got fine

Fated answered 3/3, 2017 at 2:31 Comment(0)
F
0

Put the banner in a LinearLayout just as this ,i faced the same problem and i fixed it by puting it in a linear layout

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/linearLayout">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-8056472942589154/2652831823"
        android:layout_alignBottom="@+id/saida"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</LinearLayout>
Family answered 25/9, 2015 at 18:34 Comment(1)
android:layout_alignParentTop="true" is not valid attribute of LinearLayout.Cargian
B
0

Did you go back to your admob account to register your specific app for ads and get a new longer publisher number with the 'ca-app-pub-' preface instead of the 'pub-' preface?

Nowhere in the "banner ads 1" instructions on the Google Admob "Google Mobile Ads SDK" development site does it mention having to go back to your admob account to do this.

This stupid mistake held me up for days.

Barna answered 27/4, 2017 at 11:42 Comment(0)
S
0

In my case, I had the code below under the buildscript section of the project level build.gradle

Make sure maven {url "https://maven.google.com"} is under allProjects > repositories:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}
Shoshonean answered 12/3, 2018 at 2:4 Comment(0)
D
0

Make sure that you have added Banner Ad Unit in your Admob Account and used banner appUnit-id in your adUnitId of your app where Banner Ads are displayed .

Diarmit answered 10/11, 2019 at 16:32 Comment(0)
R
0

One of reasons is that your device is not configured as device test : https://support.google.com/admob/answer/9691433

Ronna answered 12/11, 2022 at 9:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.