Eri*_*ger 2 android admob android-layout
可能重复:
如何获取Admob的设备ID
我的活动有一个ListView,我在底部放了一个广告.当我在模拟器上运行应用程序时,我会看到测试广告.当我在手机上播放时,我会收到一个实际的广告.我想在手机上测试而不是真正的广告.
我按照AdMob网站上的说明查看了logcat中的消息,说明如何手动将设备ID添加到AdRequest.问题是这条消息永远不会出现在logcat中.这是一个运行4.1的RAZR.在Aracem回答的SO帖子中,我读到编码后的字符串在Developer Options首选项面板中可用,我找到了它.当我阅读此命令的指南时,设备ID的格式是字母数字(例如"E83D20734F72FB3108F104ABC0FFC738"),但我的手机中的值包含字母,数字和短划线(例如"MQKF-RB61-BBKS-E").
我已将编码的设备ID添加到XML googleads:testDevices中,我还手动将AdRequest添加到我的onCreate中,并将addTestDevice与此字符串一起使用.都没有工作.
我注意到的一件事是有效的命名空间是googleads,而不是示例中显示的广告.当我使用广告时,我在XML中遇到前缀错误.我猜测从4.x切换到6.1,命名空间发生了变化.
我可以通过最小的项目实现这一点,其中onCreate只执行调用super和setContentView.
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_above="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
googleads:adSize="BANNER"
googleads:adUnitId="@string/admob_id"
googleads:loadAdOnCreate="true"
googleads:testDevices="TEST_EMULATOR, MQKF-RB61-BBKS-E" />
Run Code Online (Sandbox Code Playgroud)
表现
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
<application android:label="@string/app_name" >
<activity
android:name="mainActivity"
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.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
Run Code Online (Sandbox Code Playgroud)
小智 8
在Logcat中,您将找到设备ID.你会看到类似的东西
要在此设备上投放测试广告,请调用adRequest.addTestDevice(" **")
| 归档时间: |
|
| 查看次数: |
12576 次 |
| 最近记录: |