gpt4 book ai didi

java - 插页式广告不会显示

转载 作者:行者123 更新时间:2023-12-01 11:46:37 26 4
gpt4 key购买 nike

我有一个未发布的 Android 应用程序,我已使用 AdMob Interstitial Guide 插入插页式广告。并且广告最初并未展示。所以,此后我引用了Admob interstitial ad won't display我添加了这个:

interstitial.setAdListener(new AdListener(){
@Override
public void onAdLoaded(){
displayInterstitial();
}
});

而不是仅仅使用 displayInterstitial() 加载添加。执行此操作后,它仍然不会显示广告。然后我引用了“Because Admob interstitial ads won't display ”,但这没有帮助,因为我已经将 .Builder().build() 添加到 new AdRequest 中。

后来我引用了“How to show interstitial ads? ”,但这没有用,因为我正在真实设备而不是模拟器上进行测试,而且它也只是重复了 Google Interstitial Guide(第一个链接)向我展示的操作方法。然后我终于看了Interstitial Ad's Listener's onAdLoaded() won't run我在 list 中添加了互联网权限(我已经将 meta-data 属性作为 application 的子项添加到我的 list 中),并尝试使用此代码来展示广告:

interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
interstitial.show();
}
});

这也不起作用。

我有 2 个使用广告的 Activity (该应用有一个 MainActivity、一个 GameScreen Activity 和一个 Redirect Activity )

这是MainActivity(我已经排除了除涉及广告的代码之外的所有代码):

    public class MainActivity extends ActionBarActivity {

private InterstitialAd interstitial;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);



// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-3171635XXXXXXXXX/XXXXXXXXXX");
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);

interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
interstitial.show();
}
});

}

// Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}


}

这是重定向 Activity (我已经排除了除涉及广告的代码之外的所有代码,与 MainActivity 的广告显示代码相同):

public class Redirect extends ActionBarActivity {


private InterstitialAd interstitial;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_redirect);


// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-317163XXXXXXXXXX/XXXXXXXXXX");
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);

interstitial.setAdListener(new AdListener(){
@Override
public void onAdLoaded(){
super.onAdLoaded();
interstitial.show();
}
});

}

// Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}

}

这是我的 list :

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".UI.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".UI.GameScreen"
android:label="@string/title_activity_game_screen"
android:screenOrientation="landscape"
android:parentActivityName=".UI.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="benyamephrem.tilt.UI.MainActivity" />
</activity>
<activity
android:name=".UI.Redirect"
android:label="@string/title_activity_redirect"
android:screenOrientation="landscape"
android:parentActivityName=".UI.GameScreen" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="benyamephrem.tilt.UI.GameScreen" />
</activity>
</application>

我对此进行了大量研究,但尚未提出任何有效的解决方案。我觉得我错过了一些小细节,但我目前不明白为什么这不起作用。

感谢任何帮助!

最佳答案

您的 list 中缺少以下 Activity :

<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />

关于java - 插页式广告不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29090966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com