AdMob横幅广告不会出现。非插入式的工作正常

时间:2016-07-14 12:06:58

标签: android admob

MainActivity - 跳过导入部分 代码中没有可见的错误。

public class MainActivity extends AppCompatActivity {

    private AdView mAdView;
    private Button btnFullscreenAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnFullscreenAd = (Button) findViewById(R.id.btn_fullscreen_ad);
    btnFullscreenAd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, SecondActivity.class));
        }
    });

    // TODO - remove this if condition
    // it's for demo purpose
    if (TextUtils.isEmpty(getString(R.string.banner_home_footer))) {
        Toast.makeText(getApplicationContext(), "Please mention your Banner Ad ID in strings.xml", Toast.LENGTH_LONG).show();
        return;
    }

    mAdView = (AdView) findViewById(R.id.adView);

    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            // Check the LogCat to get your test device ID
            .addTestDevice("A2D6921F154FF38B4617CCCE9AAE5A61")
            .build();

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
        }

        @Override
        public void onAdClosed() {
            Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdLeftApplication() {
            Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }
    });

    mAdView.loadAd(adRequest);


}

@Override
public void onPause() {
    if (mAdView != null) {
        mAdView.pause();
    }
    super.onPause();
}

@Override
public void onResume() {
    super.onResume();
    if (mAdView != null) {
        mAdView.resume();
    }
}

@Override
public void onDestroy() {
    if (mAdView != null) {
        mAdView.destroy();
    }
    super.onDestroy();
    }
}

此相同的代码以前在同一设备上运行良好。不知何故,横幅现在无法出现。

0 个答案:

没有答案