横幅广告和非页内广告单元ID问题

时间:2014-10-16 02:25:19

标签: android admob

我正在Android中实施admob广告,但没有展示插页式广告,只显示横幅广告。 横幅广告和插页式广告是否需要在Admob Android中使用不同的广告单元ID?

任何建议

2 个答案:

答案 0 :(得分:2)

     mInterstitialAd = new InterstitialAd(this);
     mInterstitialAd.setAdUnitId("myAdUnitId");

     // Create an ad request.
     AdRequest.Builder adRequestBuilder = new AdRequest.Builder();

     // Optionally populate the ad request builder.
     adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);

     // Set an AdListener.
     mInterstitialAd.setAdListener(new AdListener() {
         @Override
         public void onAdLoaded() {
             Toast.makeText(MyActivity.this,
                     "The interstitial is loaded", Toast.LENGTH_SHORT).show();
         }

         @Override
         public void onAdClosed() {
             // Proceed to the next level.
             goToNextLevel();
         }
     });

     // Start loading the ad now so that it is ready by the time the user is ready to go to
     // the next level.
     mInterstitialAd.loadAd(adRequestBuilder.build());

     // Create the button to go to the next level.
     mNextLevelButton = new Button(this);
     mNextLevelButton.setText("Next Level");
     mNextLevelButton.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {
             // Show the interstitial if it is ready. Otherwise, proceed to the next level
             // without ever showing it.
             if (mInterstitialAd.isLoaded()) {
                 mInterstitialAd.show();
             } else {
                 // Proceed to the next level.
                 goToNextLevel();
             }
         }
     });

     // Add the next level button to the layout.
     LinearLayout layout = new LinearLayout(this);
     layout.setOrientation(LinearLayout.VERTICAL);
     layout.addView(mNextLevelButton);

     // Create a TextView to display the current level.
     mTextView = new TextView(this);
     mTextView.setText("Level 1");
     layout.addView(mTextView);

     setContentView(layout);
 }

 public void goToNextLevel() {
     // Show the next level (and disable the next level button since there are no more levels.
     mNextLevelButton.setEnabled(false);
     mTextView.setText("Level 2");
 }
}

Here is a nice example on developers.google.com

答案 1 :(得分:0)

检查您的AD类型ID。在您的admob帐户和源代码中都可以看到AD单元ID属于插页式广告。

如果那是正确的,请使用此代码

public partial class MainPage : PhoneApplicationPage
{
    private InterstitialAd interstitialAd;
      // Constructor
    public MainPage()
    {
        InitializeComponent();




        interstitialAd = new InterstitialAd("your id");
        AdRequest adReques = new AdRequest();

        interstitialAd.ReceivedAd += OnAdReceived;
        interstitialAd.LoadAd(adReques);


    }
    private void OnAdReceived(object sender, AdEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("Ad received successfully");
        interstitialAd.ShowAd();
    }