javascript - Android Eclipse 插页式广告因错误而未显示

标签 javascript android eclipse google-play-services

这是我的代码

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 list 的代码 fragment

<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 服务,并且我的应用程序正在运行,但插页式广告未显示,并且显示错误,错误消息如下:

Unsafe JavaScript attempt to access frame with URL http://googleads.g.doubleclick.net/mads/gma from frame with URL http://imasdk.googleapis.com/js/core/bridge3.1.65_en.html#goog_694420715. Domains, protocols and ports must match.

最佳答案

在创建插页式广告方法之后添加此内容

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();
        }
      }
    }

关于javascript - Android Eclipse 插页式广告因错误而未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25886390/

相关文章:

android ListView : adapter. 添加(项目)?或 adapter.notifyDataSetChanged()

java - 使用库编译项目时,java 中未找到类错误

eclipse - 如何使用构成 Gluon 项目的 iOS、android、桌面(和 main)的 Gluon 文件夹?

javascript - d3.js 双击不释放节点

javascript - 如何使用 jQuery 显示/隐藏引导微调器?

javascript - 如何使用正则表达式匹配拆分文本

android - 从 Jetpack Compose 中的流附加到 LazyList

Android AutoCompleteTextView 显示选中的

java - PythonInterpreter导入java类

Javascript 表单提交按钮不起作用 insideHTML