How can I ensure admob will appear in my app

2019-02-28 21:42发布

As we know, google requires us to use test device and test ad unit id, when we develop the app. However, I want to know that if there exists anyway that I can see the real ad, because I am afraid that no ad will show after I change the code and ad id before release. I have successfully seen test ad, and then I changed the code and ad id, and then submit my app to beta testing, but the tester said that no ad was shown, is it normal, or I have made some mistake in my code or ad unit id. Thank you for your help!

Below is my ad-related code, and I have changed the ad id

mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

标签: android admob
2条回答
我想做一个坏孩纸
2楼-- · 2019-02-28 21:50

You can use actual ad unit id even for development, but your test devices should be added to the list of TEST DEVICES when you build your ad request.

If it's a valid ad unit id that you are using, you can be sure that ads will appear when you publish your apps. Also, you can check if you are getting hits for your ad unit in Adsense Dashboard.

If you want to be dead sure, you can just try to install the apk on another device, test it, and then publish it when you see the ads.

查看更多
劫难
3楼-- · 2019-02-28 21:56

You can use AdListener and monitor why it is not showing ads . Remember if you have created fresh ad units then it will take some time or few hours to arrange live ads for it . If test ads are showing and you have valid ad unit id and also your app has not violated any policy then you are good to go (You will be emailed if your app have a policy issue) . Ads will be shown when availabe.

AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest1 = new AdRequest.Builder().build();
adView.loadAd(adRequest1);
adView.setAdListener(new AdListener() {
  @Override
  public void onAdLoaded() {
    // Code to be executed when an ad finishes loading.
    Log.i("Ads", "onAdLoaded");
  }

  @Override
  public void onAdFailedToLoad(int errorCode) {
    // Code to be executed when an ad request fails.


    switch (errorCode){
      case AdRequest.ERROR_CODE_INTERNAL_ERROR:
        Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_INTERNAL_ERROR",Toast.LENGTH_SHORT).show();
        break;
      case AdRequest.ERROR_CODE_INVALID_REQUEST:
        Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_INVALID_REQUEST",Toast.LENGTH_SHORT).show();
        break;
      case AdRequest.ERROR_CODE_NETWORK_ERROR:
        Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_NETWORK_ERROR",Toast.LENGTH_SHORT).show();
        break;
      case AdRequest.ERROR_CODE_NO_FILL:
        Toast.makeText(PlayListsActivity.this,"onAdFailedToLoad banner ERROR_CODE_NO_FILL",Toast.LENGTH_SHORT).show();
        break;
    }
    Log.i("Ads", "onAdFailedToLoad");
  }

  @Override
  public void onAdOpened() {
    // Code to be executed when an ad opens an overlay that
    // covers the screen.
    Log.i("Ads", "onAdOpened");
  }

  @Override
  public void onAdLeftApplication() {
    // Code to be executed when the user has left the app.
    Log.i("Ads", "onAdLeftApplication");
  }

  @Override
  public void onAdClosed() {
    // Code to be executed when when the user is about to return
    // to the app after tapping on an ad.
    Log.i("Ads", "onAdClosed");
  }
});
查看更多
登录 后发表回答