我有一个未发布的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 Ad's Listener's onAdLoaded() won't run并在我的清单中添加了Internet权限(我已经将meta-data
属性添加到我的清单中作为application
的孩子)并尝试使用此代码来显示广告:
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
interstitial.show();
}
});
这也不起作用。
我有两项使用广告的活动(该应用包含MainActivity
,GameScreen
活动和Redirect
活动
以下是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();
}
}
}
以下是重定向活动(我已排除了除广告所涉及代码之外的所有代码,与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();
}
}
}
这是我的清单:
<?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>
我已经对此进行了大量研究,但我还没有提出任何有效的解决方案。我觉得我错过了一些小细节,但我现在无法理解为什么这不起作用。
任何帮助表示赞赏!
答案 0 :(得分:1)
您在清单中缺少以下活动:
<!--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" />