有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android Admob未在emulator中显示它为空

我一直在遵循安卓快速入门教程https://developers.google.com/mobile-ads-sdk/docs/admob/安卓/quick-start将Admob放在模拟器上,但它不起作用,可能缺少什么。我基本上是逐字复制了教程,但它不起作用。我还检查了我的日志,发现这个错误找不到类的安卓。应用程序。AppOpsManager’,引用自方法com。谷歌。安卓gms。常见的谷歌PlayServiceSutil。zza。这似乎是他们的内部错误。我也刚刚升级到新的Android Studio 1.2.1.1。这是我的基本代码

Main。java

  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    }

acitivity\u main。xml

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:tools="http://schemas.安卓.com/tools" 安卓:layout_width="match_parent"
    xmlns:ads="http://schemas.安卓.com/apk/res-auto"
    安卓:layout_height="match_parent" 安卓:paddingLeft="@dimen/activity_horizontal_margin"
    安卓:paddingRight="@dimen/activity_horizontal_margin"
    安卓:paddingTop="@dimen/activity_vertical_margin"
    安卓:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Main">

    <TextView 安卓:text="@string/hello_world" 安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content" />

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

</RelativeLayout>

AndroidManifest。xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    package="com.example" >
    <uses-permission 安卓:name="安卓.permission.INTERNET"/>
    <uses-permission 安卓:name="安卓.permission.ACCESS_NETWORK_STATE"/>
    <application
        安卓:allowBackup="true"
        安卓:icon="@mipmap/ic_launcher"
        安卓:label="@string/app_name"
        安卓:theme="@style/AppTheme" >
        <meta-data 安卓:name="com.google.安卓.gms.version"
            安卓:value="@integer/google_play_services_version" />
        <activity
            安卓:name=".Main"
            安卓:label="@string/app_name" >
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 安卓:name="com.google.安卓.gms.ads.AdActivity"
            安卓:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            安卓:theme="@安卓:style/Theme.Translucent" />
    </application>

</manifest>

Gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.安卓.support:appcompat-v7:22.0.0'
    compile 'com.google.安卓.gms:play-services:7.3.0'
}

字符串XML

<resources>
    <string name="app_name">AdsenseCalculator</string>
    <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
</resources>

共 (1) 个答案

  1. # 1 楼答案

    将以下内容添加到代码中:

    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)    // remove when exporting signed APK
            .addTestDevice(getDeviceId())       // remove when exporting signed APK
            .build();