我在我的Android游戏中添加了AdMob代码,但广告没有显示。检查LogCat并收到广告,查看我的AdMob帐户和游戏变绿,请求是100%填充率好。我没有触摸xml,只是onCreate。请告诉我是否可以用xml或其他任何东西做。我把所有权限都放在了清单中。请看看并帮助,已经10天遇到麻烦了。谢谢
我的代码:
Window window = getWindow();
RelativeLayout adsLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);
// Displays Ads at the bottom of your sketch, use Gravity.TOP to display them at the top
adsLayout.setGravity(Gravity.TOP);
AdView adView = new AdView(this, AdSize.BANNER, "myid"); // add your app-id
adsLayout.addView(adView);
AdRequest newAdReq = new AdRequest();
//Remark: uncomment next line for testing your Ads (fake ads)
newAdReq.setTesting(false);
adView.loadAd(newAdReq);
window.addContentView(adsLayout,lp2);
Android Manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
<activity android:name=".MYGAMENAME"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="orientation|screenLayout">
<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>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
我的Main.xml:
的xmlns:机器人= “http://schemas.android.com/apk/res/android” 机器人:方向=“垂直” 机器人:layout_width = “FILL_PARENT” 机器人:layout_height = “FILL_PARENT”