我确定我的代码是正确的,因为我可以看到测试AdMob
。
但是当我尝试在banner_ad_unit_id
上使用发布ID时,我无法看到它。为什么?我的敬仰请求可能会少得多吗?
我的layout.xml设置:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
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>
AdMob代码设置:
AdView adView = new AdView(getActivity());
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(getResources().getString(R.string.banner_ad_unit_id));
mAdView = (AdView) view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
我还在我的清单上添加了权限:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tw.idv.morton.mydailysugar">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/medical_history512"
android:label="@string/myAppName"
android:roundIcon="@drawable/medical_history512"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
<!-- This meta-data tag is required to use Google Play Services. -->
<!-- 2. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustUnspecified|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- 3. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</manifest>
它将显示请求错误:
06-27 17:20:42.819 1635-1635/tw.idv.morton.mydailysugar I/Ads: Starting ad request.
06-27 17:20:42.819 1635-1635/tw.idv.morton.mydailysugar I/Ads: Use AdRequest.Builder.addTestDevice("D4C3A767DB14E4027B1AD9084862CC62") to get test ads on this device.
06-27 17:20:43.308 1635-1661/tw.idv.morton.mydailysugar W/Ads: There was a problem getting an ad response. ErrorCode: 0
06-27 17:20:43.310 1635-1635/tw.idv.morton.mydailysugar W/Ads: Failed to load ad: 0
06-27 17:20:43.311 1635-1635/tw.idv.morton.mydailysugar I/Ads: onAdFailedToLoad
我真的不知道原因。我希望看到真实的广告,有人可以告诉我我错过了哪一步。