[英]Interstitial Ad Will Not Display
I have an unpublished Android app that I have inserted interstitial ads into using the AdMob Interstitial Guide and the ads did not initially show. 我有一个未发布的Android应用程序,我已经使用AdMob插页式指南插入了插页式广告,但广告最初并未展示。 So, thereafter I referenced Admob interstitial ad won't display and I added this:
因此,此后我引用了Admob插页式广告,因此不会显示,并添加了以下内容:
interstitial.setAdListener(new AdListener(){
@Override
public void onAdLoaded(){
displayInterstitial();
}
});
Instead of just loading the add using displayInterstitial()
. 而不是仅仅使用
displayInterstitial()
加载添加项。 After doing this it still will not show the ads. 完成此操作后,仍然不会展示广告。 Then I referenced " Because Admob interstitial ads won't display " and that did not help because I had already added
.Builder().build()
to the new AdRequest
. 然后,我引用了“ 因为Admob插页式广告不会显示 ”,这并没有帮助,因为我已经将
.Builder().build()
到了new AdRequest
。
Afterwards I referenced " How to show interstitial ads? " and that was not useful because I am testing on a real device and not an emulator, and it also just repeated what the Google Interstitial Guide (first link) showed me how to do. 之后,我引用了“ 如何显示插页式广告? ”,它没有用,因为我是在真实设备上而不是在模拟器上进行测试,并且它也重复了Google插页式指南(第一个链接)向我展示的操作方法。 Then I finally looked at Interstitial Ad's Listener's onAdLoaded() won't run and I added the Internet permission in my manifest (I had already added the
meta-data
property to my manifest as a child of application
) and tried this code to show the ad: 然后,我最终查看了Interstitial Ad的Listener的onAdLoaded()无法运行,并在清单中添加了Internet许可(我已经将
meta-data
属性作为application
的子项添加到清单中),并尝试使用此代码来显示广告:
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
interstitial.show();
}
});
And that did not work either. 那也不起作用。
I have 2 activities using ads (the app has a MainActivity
, a GameScreen
activity, and a Redirect
activity) 我有2个使用广告的活动(该应用程序具有
MainActivity
, GameScreen
活动和Redirect
活动)
Here is the MainActivity (I have excluded all the code except the ad involved code): 这是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();
}
}
}
Here is the Redirect activity (I have excluded all the code except the ad involved code, identical to the MainActivity's ad showing code): 这是重定向活动(我已排除了所有代码,但涉及广告的代码除外,与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();
}
}
}
Here is my Manifest: 这是我的清单:
<?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>
I have heavily researched this and I haven't come up with any solution that has worked. 我对此进行了大量研究,但没有提出任何可行的解决方案。 I feel like I'm missing some small detail but I can't currently see why this is not working.
我觉得我缺少一些小细节,但目前无法理解为什么它不起作用。
Any help appreciated! 任何帮助表示赞赏!
You are missing the following activity in your manifest: 您的清单中缺少以下活动:
<!--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" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.