2015-12-31 61 views
0

我从谷歌的跟踪代码,我尝试运行此代码并没有什么广告只是有错误和不;吨展示广告AdMob联播Android的广告错误

这是主类 公共类MyActivity扩展ActionBarActivity {

private static final long GAME_LENGTH_MILLISECONDS = 3000; 

private PublisherInterstitialAd mInterstitialAd; 
private CountDownTimer mCountDownTimer; 
private Button mRetryButton; 
private boolean mGameIsInProgress; 
private boolean mAdIsLoading; 
private long mTimerMilliseconds; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_my); 

    // Create the InterstitialAd and set the adUnitId. 
    mInterstitialAd = new PublisherInterstitialAd(this); 
    // Defined in res/values/strings.xml 
    mInterstitialAd.setAdUnitId(getString(R.string.ad_unit_id)); 

    mInterstitialAd.setAdListener(new AdListener() { 
     @Override 
     public void onAdClosed() { 
      startGame(); 
     } 

     @Override 
     public void onAdLoaded() { 
      mAdIsLoading = false; 
     } 

     @Override 
     public void onAdFailedToLoad(int errorCode) { 
      mAdIsLoading = false; 
     } 
    }); 

    // Create the "retry" button, which tries to show an interstitial between game plays. 
    mRetryButton = ((Button) findViewById(R.id.retry_button)); 
    mRetryButton.setVisibility(View.INVISIBLE); 
    mRetryButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      showInterstitial(); 
     } 
    }); 

    startGame(); 
} 

private void createTimer(final long milliseconds) { 
    // Create the game timer, which counts down to the end of the level 
    // and shows the "retry" button. 
    if (mCountDownTimer != null) { 
     mCountDownTimer.cancel(); 
    } 

    final TextView textView = ((TextView) findViewById(R.id.timer)); 

    mCountDownTimer = new CountDownTimer(milliseconds, 50) { 
     @Override 
     public void onTick(long millisUnitFinished) { 
      mTimerMilliseconds = millisUnitFinished; 
      textView.setText("seconds remaining: " + ((millisUnitFinished/1000) + 1)); 
     } 

     @Override 
     public void onFinish() { 
      mGameIsInProgress = false; 
      textView.setText("done!"); 
      mRetryButton.setVisibility(View.VISIBLE); 
     } 
    }; 
} 

@Override 
public void onResume() { 
    // Start or resume the game. 
    super.onResume(); 

    if (mGameIsInProgress) { 
     resumeGame(mTimerMilliseconds); 
    } 
} 

@Override 
public void onPause() { 
    // Cancel the timer if the game is paused. 
    mCountDownTimer.cancel(); 
    super.onPause(); 
} 

private void showInterstitial() { 
    // Show the ad if it's ready. Otherwise toast and restart the game. 
    if (mInterstitialAd != null && mInterstitialAd.isLoaded()) { 
     mInterstitialAd.show(); 
    } else { 
     Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show(); 
     startGame(); 
    } 
} 

private void startGame() { 
    // Request a new ad if one isn't already loaded, hide the button, and kick off the timer. 
    if (!mAdIsLoading && !mInterstitialAd.isLoaded()) { 
     mAdIsLoading = true; 
     PublisherAdRequest adRequest = new PublisherAdRequest.Builder().addTestDevice("98C0D5CB2DE5053D838806F85C1F9AE5").build(); 
     mInterstitialAd.loadAd(adRequest); 
    } 

    mRetryButton.setVisibility(View.INVISIBLE); 
    resumeGame(GAME_LENGTH_MILLISECONDS); 
} 

private void resumeGame(long milliseconds) { 
    // Create a new timer for the correct length and start it. 
    mGameIsInProgress = true; 
    mTimerMilliseconds = milliseconds; 
    createTimer(milliseconds); 
    mCountDownTimer.start(); 
} 

}

这是错误当我尝试代码

19367/com.google.android.gms.example.interstitialexample I/Ads: Starting ad request. 
12-31 14:23:32.885 19367- 
12-31 14:23:32.915 19367-19367/com.google.android.gms.example.interstitialexample D/Atlas: Validating map... 
12-31 14:23:33.075 19367-19367/com.google.android.gms.example.interstitialexample D/FindExtension: FindExtension: before mHardwareRenderer.initialize, mSurface.isValid() = true 
12-31 14:23:43.225 19367-19384/com.google.android.gms.example.interstitialexample W/Ads: There was a problem getting an ad response. ErrorCode: 0 
12-31 14:23:43.245 19367-19367/com.google.android.gms.example.interstitialexample W/Ads: Failed to load ad: 0 

代码运行正常,但不显示插页式广告

+0

看到这里http://stackoverflow.com/questions/26313488/admob-banner-and-interstitial-ads-not-loading-on-launcher-activity – Tauqir

+0

我试着用其他包名和没有人:(我有其他的应用程序,我看不到广告。Google从来没有给我发过邮件@Tauqir – Heisenberg06

回答

0

只需等待一两天,它就会自动修复。我也看到过这种情况。代码没有任何问题。

此外,我希望你尝试了一个设备,而不仅仅是模拟器。如果还没有尝试在实际的Android设备上尝试它。