【问题标题】:Android Eclipse Interstitial Ads not showing for an errorAndroid Eclipse Interstitial Ads 未显示错误
【发布时间】:2014-09-17 09:05:13
【问题描述】:

这是我的代码

package mypackegename;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.*;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {

  private InterstitialAd interstitial;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create the interstitial.
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId("ca-app-pub-xxxxxxxxxxxxx/xxxxxxxxxx");

    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);
    displayInterstitial();
  }

  // Invoke displayInterstitial() when you are ready to display an interstitial.
  public void displayInterstitial() {
    if (interstitial.isLoaded()) {
      interstitial.show();
    }
  }
}

这是Android manifest的代码sn-p

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    <!-- Include required permissions for Google Mobile Ads to run-->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
         <!--This meta-data tag is required to use Google Play Services.-->
        <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
            <!--Include the AdActivity configChanges and theme. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
    </application>

我还导入了 google play 服务,我的应用正在运行,但插页式广告没有显示,并且出现错误,错误消息如下:

不安全的 JavaScript 尝试从 URL 为 http://imasdk.googleapis.com/js/core/bridge3.1.65_en.html#goog_694420715 的框架访问 URL 为 http://googleads.g.doubleclick.net/mads/gma 的框架。域、协议和端口必须匹配。

【问题讨论】:

    标签: javascript android eclipse google-play-services


    【解决方案1】:

    在创建插页式广告方法后添加此项

    interstitialAd.setAdListener(new AdListener(){
                  public void onAdLoaded(){
                       displayInterstitial();
                  }
        });
    

    这边

    public class Interstitial extends Activity {
    
          private InterstitialAd interstitialAd;
    
          /** Your ad unit id. Replace with your actual ad unit id. */
          private static final String AD_UNIT_ID = "ca-xxxxxxxxxxxxxxxxxxxxxxxx";
    
          @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_juego);
    
            // Create the interstitial.
            interstitialAd = new InterstitialAd(this);
            interstitialAd.setAdUnitId(AD_UNIT_ID);
    
            // Create ad request.
            AdRequest adRequest = new AdRequest.Builder().build();
    
            // Begin loading your interstitial.
            interstitialAd.loadAd(adRequest);
    
            interstitialAd.setAdListener(new AdListener(){
                  public void onAdLoaded(){
                       displayInterstitial();
                  }
        });
    
          }
    
          // Invoke displayInterstitial() when you are ready to display an interstitial.
          public void displayInterstitial() {
            if (interstitialAd.isLoaded()) {
              interstitialAd.show();
            }
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-20
      • 2012-09-22
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 2016-02-18
      相关资源
      最近更新 更多