【问题标题】:Ads with AdMob and Google Play Services Library doesnt show on device带有 AdMob 和 Google Play 服务库的广告不会在设备上显示
【发布时间】:2019-11-29 22:00:41
【问题描述】:

我在使用 AdMob 和 Google Play 服务时遇到了一个问题,这让我疯狂了好几天。感觉几乎不可能完成这项工作。这个实现有什么问题?

layout.xml(下面的代码在布局的底部):

xmlns:ads="http://schemas.android.com/apk/res-auto"
...
    <LinearLayout
        android:id="@+id/layoutAd"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_marginTop="5dp"
        android:layout_weight="3"
        android:orientation="vertical" >

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

    </LinearLayout>

MainActivity.java:

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;

...
adView = (AdView)this.findViewById(R.id.adView);  
AdRequest request = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR).
        addTestDevice("9234EBAE83E894E6271DEBE7B380782E").build();              
adView.loadAd(request);

AndroidManifest.xml:

<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    ...
            <activity android:name="com.google.android.gms.ads.AdActivity"
                android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

LogCat:

Use AdRequest.Builder.addTestDevice("9234EBAE83E894E6271DEBE7B380782E") to get test ads on this device.

GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

SQLiteLog: (14) cannot open file at line 30241 of [00bb9c9ce4]

SQLiteLog: (14) os_unix.c:30241: (2) open(/NotificationPermissions.db) -

广告永远不会出现,但如果我在模拟器上运行它,它就会出现。

我哪里错了?

【问题讨论】:

标签: android android-emulator admob device


【解决方案1】:

尝试阅读thisthis...;)

【讨论】:

    【解决方案2】:

    我的建议注释代码

    addTestDevice("9234EBAE83E894E6271DEBE7B380782E").build();

    并连接您的手机,确保计算机检测到您的手机 并运行项目,您的设备应出现在要运行的选择设备上 点击确定

    希望能帮到你

    最后的建议,如果您使用 Eclipse,请在顶部菜单中转到 Project 点击 很多时候这会清除工作区中的垃圾数据

    【讨论】:

      【解决方案3】:

      尝试使用:

      import com.google.android.gms.ads.*;
      

      代替:

      import com.google.android.gms.ads.AdRequest;
      import com.google.android.gms.ads.AdView;
      import com.google.android.gms.ads.AdSize;
      

      这为我解决了一些问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多