根据AdMob tutorial,我尝试在我的片段中显示测试广告。
我的片段XML中包含以下代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.myapp.DetailFragment">
<TextView
android:id="@+id/txvTitle"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"/>
<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">
</com.google.android.gms.ads.AdView>
</LinearLayout>
banner_ad_unit_id 取自教程(作为测试ID):
<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
我的片段类中有以下代码:
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
AdView mAdView = (AdView) view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(MY_TEST_ID_BY_ADS_LOG)
.build();
mAdView.loadAd(adRequest);
}
根据AdMob教程,测试广告应该可见。
我在日志中遇到的是一个奇怪的编解码器错误然后错误0 和错误3 :
02-06 15:45:01.003 12285-12285/com.example.myapp.free E/AppStreamingFragment: [MediaCodecRenderer] Failed to initialize codec supporting video/avc
java.lang.IllegalArgumentException
at android.media.MediaCodecList.getCodecCapabilities(Native Method)
at android.media.MediaCodecInfo.getCapabilitiesForType(MediaCodecInfo.java:211)
at com.google.android.libraries.appstreaming.framework.j.a(SourceFile:82)
at com.google.android.libraries.appstreaming.framework.d.<init>(SourceFile:18)
at com.google.android.gms.ads.internal.overlay.ay.<clinit>(SourceFile:11)
at com.google.android.gms.ads.internal.t.a(SourceFile:14)
at com.google.android.gms.ads.l.a(SourceFile:61)
at com.google.android.gms.ads.AdManagerCreatorImpl.a(SourceFile:99)
at com.google.android.gms.ads.internal.client.ah.onTransact(SourceFile:91)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.ads.internal.client.zzv$zza$zza.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zze.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zze.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zzab.zzdh(Unknown Source)
at com.google.android.gms.ads.internal.client.zzab.zzdg(Unknown Source)
at com.google.android.gms.ads.internal.client.zzab.zza(Unknown Source)
at com.google.android.gms.ads.BaseAdView.loadAd(Unknown Source)
at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
at ccom.example.myapp.free.DetailFragment.onViewCreated(DetailFragment.java:126)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:843)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
at android.app.BackStackRecord.run(BackStackRecord.java:635)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4802)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580)
at dalvik.system.NativeStart.main(Native Method)
02-06 15:45:01.099 12371-12371/com.example.myapp.free I/Ads: Starting ad request.
02-06 15:45:01.619 498-1530/? I/ActivityManager: Start proc com.google.android.gms for service com.google.android.gms/.ads.AdRequestBrokerService: pid=12569 uid=10010 gids={3003, 1015, 1028, 2001, 1007, 3006, 1006, 3002, 3001}
02-06 15:45:02.499 12569-12569/? I/ActivityThread: Pub com.google.android.gms.download: com.google.android.gms.common.download.provider.DownloadsProvider
02-06 15:45:02.539 12569-12569/? I/ActivityThread: Pub com.google.android.gms.ads.adinfo: com.google.android.gms.ads.adinfo.AdvertisingInfoContentProvider
02-06 15:45:05.599 12569-12569/? W/dalvikvm: VFY: unable to resolve virtual method 8548: Lcom/google/android/gms/ads/internal/u/k;.isAttachedToWindow ()Z
02-06 15:45:07.499 12371-12384/com.example.myapp.free I/Ads: No fill from ad server.
02-06 15:45:07.499 12371-12371/com.example.myapp.free I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-06 15:45:07.499 12371-12371/com.example.myapp.free W/Ads: Failed to load ad: 3
02-06 15:46:07.599 12371-12371/com.example.myapp.free I/Ads: Starting ad request.
02-06 15:46:07.989 12371-12384/com.example.myapp.free I/Ads: No fill from ad server.
02-06 15:46:07.989 12371-12371/com.example.myapp.free I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-06 15:46:07.989 12371-12371/com.example.myapp.free W/Ads: Failed to load ad: 3
02-06 15:47:08.009 12371-12371/com.example.myapp.free I/Ads: Starting ad request.
02-06 15:47:08.479 12371-12384/com.example.myapp.free I/Ads: No fill from ad server.
02-06 15:47:08.479 12371-12371/com.example.myapp.free I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-06 15:47:08.479 12371-12371/com.example.myapp.free W/Ads: Failed to load ad: 3
02-06 15:48:08.509 12371-12371/com.example.myapp.free I/Ads: Starting ad request.
02-06 15:48:08.829 12371-12385/com.example.myapp.free I/Ads: No fill from ad server.
02-06 15:48:08.829 12371-12371/com.example.myapp.free I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-06 15:48:08.829 12371-12371/com.example.myapp.free W/Ads: Failed to load ad: 3
02-06 15:49:08.889 12371-12371/com.example.myapp.free I/Ads: Starting ad request.
02-06 15:49:09.359 12371-12385/com.example.myapp.free I/Ads: No fill from ad server.
02-06 15:49:09.359 12371-12371/com.example.myapp.free I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-06 15:49:09.369 12371-12371/com.example.myapp.free W/Ads: Failed to load ad: 3
02-06 15:50:09.429 12371-12371/com.example.myapp.free I/Ads: Starting ad request.
02-06 15:50:09.989 12569-16804/? W/Ads: Received error HTTP response code: 403
02-06 15:50:09.989 12371-12384/com.example.myapp.free W/Ads: There was a problem getting an ad response. ErrorCode: 0
02-06 15:50:09.989 12371-12371/com.example.myapp.free W/Ads: Failed to load ad: 0
我还应该设置什么?