0

我在我的 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);

安卓清单:

<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:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"

4

0 回答 0