在我的應用中,我想展示插頁式廣告。經過10場比賽後,應該顯示,所以我設置了一個櫃檯,看看有多少場比賽。在我的模擬器上,int playcount;
重置,AdMobs測試廣告彈出。在真實設備上,int playcount
會一直計數,並且不會顯示任何廣告。它可能有什麼問題?android - 插頁式廣告只在模擬器上彈出
public class GameScreen extends Activity {
public int playcount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
TextView playctv = (TextView) findViewById(R.id.textView);
mInterstitialAd = new InterstitialAd(this);
// set the ad unit ID
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
AdRequest adRequest = new AdRequest.Builder()
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
SharedPreferences prefsplay = this.getSharedPreferences("myPrefsKey",
Context.MODE_PRIVATE);
playcount = prefsplay.getInt("play_number", 0);
playctv.setText(String.valueOf(playcount));
AdView mAdView = (AdView) findViewById(R.id.adView);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-xxxxx");
AdRequest adRequestd = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
}
public void restart(View view) {
Intent intent = new Intent(this, GameScreen.class);
startActivity(intent);
playcount++;
SharedPreferences prefsplay = this
.getSharedPreferences("myPrefsKey",
Context.MODE_PRIVATE);
prefsplay.edit().putInt("play_number", playcount)
.apply();
}
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
public void gameover() {
if(playcount == 10) {
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
playcount = 0;
}
});
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
// Check the LogCat to get your test device ID
.addTestDevice("C04B1BFFB0774708339BC273F8A43708")
.build();
}
}
因爲這addTestDevice(AdRequest.DEVICE_ID_EMULATOR)的 –
@KhalilM你想,如果這部分被刪除它是否行得通呢? –
嘗試刪除它並添加AdRequest adRequest = new AdRequest.Builder()。build(); mInterstitialAd.loadAd(adRequest); –