interstitial.setAdListener(new AdListener(){
public void onAdLoaded(){
display();
}
});
我尝试使用调试器,第一行已运行,但第二行根本没有运行。这就是我在onCreate方法中初始化广告的方式:
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("******************************");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
在类中的方法之外的和InterstitialAd interstitial;
。 AdUnitId故意被删除。
logcat的:
05-17 20:10:49.802: E/GooglePlayServicesUtil(17509): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-17 20:10:49.807: E/GooglePlayServicesUtil(17509): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-17 20:10:51.597: I/GATE(17509): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
05-17 20:10:51.597: I/Ads(17509): Scheduling ad refresh 60000 milliseconds from now.
05-17 20:10:51.602: I/Ads(17509): Ad finished loading.
05-17 20:10:51.632: D/TilesManager(17509): Starting TG #0, 0x5b3446f0
05-17 20:10:51.632: D/TilesManager(17509): new EGLContext from framework: 593202c0
05-17 20:10:51.632: D/GLWebViewState(17509): Reinit shader
05-17 20:10:51.632: D/GLWebViewState(17509): Reinit transferQueue
05-17 20:10:56.262: D/AbsListView(17509): Get MotionRecognitionManager
05-17 20:11:31.987: I/Ads(17509): Ad is not visible. Not refreshing ad.
05-17 20:11:31.992: I/Ads(17509): Scheduling ad refresh 60000 milliseconds from now.
答案 0 :(得分:0)
希望您在AndroidManifest.xml中添加以下内容
互联网许可
<uses-permission android:name="android.permission.INTERNET"/>
AdActivity
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
应用标记下的Google Play服务lib
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
并添加了代码
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(getResources().getString(R.string.admob_inst));
// interstitial.setAdUnitId("01010101");
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
interstitial.show();
}
});
答案 1 :(得分:0)
你是否在onAdLoaded()方法之前缺少@override
答案 2 :(得分:0)
请勿从#onAdLoaded调用display()。这将导致非常糟糕的用户体验。而是从应用程序中的自然断点调用显示(如果广告已加载)。
此外,您的日志中的这些行表明您还有横幅广告。
05-17 20:11:31.987: I/Ads(17509): Ad is not visible. Not refreshing ad.
05-17 20:11:31.992: I/Ads(17509): Scheduling ad refresh 60000 milliseconds from now.
如果情况并非如此,那么您的adUnit配置错误,因为您正在进行自动刷新,这对于插页式广告不会发生。您需要每次都明确加载插页式广告。
答案 3 :(得分:0)
使用以下代码在AdLoaded()上显示广告的监听器。我用过同样的东西。它对我有用。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("***********");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
}
外部oncreate函数使用下面的代码:
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}