2014-09-17 2 views
0

Это мой кодAndroid Eclipse, межстраничные объявления не показываются по ошибке

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 манифеста

<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://googleads.g.doubleclick.net/mads/gma из фрейма с URL http://imasdk.googleapis.com/js/core/bridge3.1.65_en.html#goog_694420715. Домены, протоколы и порты должны совпадать.

ответ

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

Благодаря человеку в настоящее время он работает. : D –

+1

Ваше приветствие;) –

Смежные вопросы