简体   繁体   English

Android Admob未在模拟器中显示为空白

[英]Android Admob not showing in emulator it is blank

I have been following the android quick start tutorial https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start to put Admob on the emulator and it is not working what could be missing.I have essentially copied the tutorial word for word and it does not work.Also I have checked my Logcat and got this error Could not find class 'android.app.AppOpsManager',referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza . 我一直在遵循android快速入门教程https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start将Admob放在模拟器上,但它不起作用,可能会丢失什么。我基本上已经逐字逐句地复制了教程,但它不起作用。我也检查了Logcat并收到此错误找不到方法com.google.android.gms.common引用的类“ android.app.AppOpsManager”。 GooglePlayServicesUtil.zza That seems to be an internal error with them.I have also just upgraded to the new Android Studio 1.2.1.1 for what it is worth .Here is my basic code 这似乎是他们的内部错误。我还刚刚升级到新的Android Studio 1.2.1.1,这是我的基本代码

Main.java 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_main.xml acitivity_main.xml

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

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

    <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="@string/banner_ad_unit_id"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

AndroidManifest.xml AndroidManifest.xml

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

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

</manifest>

Gradle 摇篮

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

Strings XML 字符串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>

Add this to your code: 将此添加到您的代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM