首页 文章

AdMob Banner 广告未显示

提问于
浏览
15

我在我的应用程序中使用admob,它工作正常但突然停止显示广告 . 贝娄是我使用的代码:

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" />

我按照adMob网站上的所有说明进行操作,因为我说它几天前正在运行 .

来自logcat的Bellow很少,可能与我的问题有关:

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

我反复收到波纹管警告,当我点击广告应该显示的空白区域时,它会显得更多

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

这是带有“广告”的过滤logcat

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.

我到处寻找解决方案,并且看了一些类似的,但没有他们帮我 .

7 回答

  • 1

    使用下面的代码行

    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 );
    

    而不是使用这个

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

    因为当您的应用程序准备好在Google Play商店发布时,系统会使用此行 .

    您可以将设备的ID替换为 "AC98C820A50B4AD8A2106EDE96FB87D4" . 获取设备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

  • 14

    通过手动卸载应用程序并重新安装,无需进行任何更改即可解决此问题!

  • 2

    检查您是否拥有最新版本的adMob和GooglePlayServices lib .

  • 8

    把 Banner 放在LinearLayout就像这样,我面临同样的问题,我通过将其置于线性布局来修复它

    <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>
    
  • 0

    在我的情况下,广告没有显示,直到我给它足够的空间 .

    在此之前

    <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"/>
    

    这里的adview具有wrap_content的高度,因此它调整自身以实现其高度,但其父级(LinearLayout)具有90dip的严格高度,这不允许adView占用足够的空间来显示广告 .

    所以我所做的只是将LinearLayout的高度改为wrap_content然后事情就好了

  • 1

    您是否返回到您的admob帐户注册特定的广告应用,并使用“ca-app-pub-”前言而不是“pub-”前言获得新的更长的发布商编号?

    谷歌Admob“谷歌移动广告SDK”开发网站上的“ Banner 广告1”说明中没有提到必须返回到您的admob帐户才能执行此操作 .

    这个愚蠢的错误让我困扰了好几天 .

  • 0

    在我的情况下,我在项目级 build.gradlebuildscript 部分下面有代码

    确保 maven {url "https://maven.google.com"}allProjects > repositories 下:

    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }
    

相关问题