问题
interstitial.setAdListener(new AdListener(){
public void onAdLoaded(){
display();
}
});
I tried with the debugger, the 1st line was run, but the second line was simply not run. This is how I initialize the ad in the onCreate method:
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("******************************");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
and InterstitialAd interstitial;
outside of the method inside the class. The AdUnitId was deliberately blanked out.
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.
回答1:
Are you missing @override before onAdLoaded() method
回答2:
Hope you have added following in AndroidManifest.xml
Internet permission
<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 service lib under application tag
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
And added code as
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();
}
});
回答3:
Do NOT call display() from #onAdLoaded. This will results is a very poor UX. Instead call display from a natural break point in your application (if an ad has been loaded).
Also these lines in your logs suggest that you also have banner ads.
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.
If that is not the case then you have misconfigured your adUnit because you are getting auto refresh which does not happen for an interstitial. You need to explicitly load an interstitial each time.
回答4:
Use the following code to display the ad's listener on AdLoaded(). I used the same. It was worked for me.
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();
}
});
}
Outside oncreate function use below code:
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
来源:https://stackoverflow.com/questions/23710521/interstitial-ads-listeners-onadloaded-wont-run