2014-09-04 105 views
0

我遵循关于插页式广告的Google教程,但每当我尝试显示我的广告时,它都不会被加载。我试过使用AdListener而不是interstitial.isLoaded,但结果仍然相同。我也给了广告超过2分钟来加载几次,所以有些事情一定是错的。广告未加载

我正在使用AVD,这可能是问题吗?当我使用浏览器时,它可以连接到互联网。

卸下了不正确的链接

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.JrodManU.LaserJumper.android" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="23" /> 
    <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/GdxTheme" > 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
     <activity 
      android:name=".AndroidLauncher" 
      android:clearTaskOnLaunch="true" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 
</manifest> 

AndroidLauncher

package com.JrodManU.LaserJumper.android; 

import android.os.Bundle; 

import com.badlogic.gdx.backends.android.AndroidApplication; 
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; 
import com.google.android.gms.ads.*; 
import com.JrodManU.LaserJumper.GameEventListener; 
import com.JrodManU.LaserJumper.LaserJumper; 

public class AndroidLauncher extends AndroidApplication implements GameEventListener { 
    private InterstitialAd interstitial; 
    boolean showed = false; 
    boolean loaded = false; 
    @Override 
    protected void onCreate (Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); 
     initialize(new LaserJumper(this), config); 

     interstitial = new InterstitialAd(this); 
     interstitial.setAdUnitId("******"); 
     AdRequest adRequest = new AdRequest.Builder() 
     .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
     //.addTestDevice(testDeviceId) 
     .build(); 
     interstitial.loadAd(adRequest); 
     interstitial.setAdListener(new AdListener(){ 
      public void onAdLoaded(){ 
       loaded = true; 
      } 
     }); 
    } 

    public boolean displayInterstitial() { 
     this.runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       if(loaded) { 
        interstitial.show(); 
        showed = true; 
       } else { 
        System.out.println("failed"); //Always prints failed 
        showed = false; 
       } 
      } 
     }); 
     return showed; 
    } 
} 
+0

你已经在谷歌AdMob联播仪表板创建插页式广告单元? – donfuxx 2014-09-04 22:03:09

+0

同时检查logcat输出(过滤标签:广告)。 Admob会在广告完成加载时进行日志记录,并且还会记录该事件出错的情况。 – donfuxx 2014-09-04 22:16:48

+1

“无法找到com.google.android.gms.ads.AdActivity,请确保它在AndroidManifest.xml中声明”猜猜我没有做xml权利。 – JrodManU 2014-09-04 22:27:17

回答

2

如果您收到此错误:

could not find com.google.android.gms.ads.AdActivity, please make sure it is declared in AndroidManifest.xml

然后加入本次活动的声明在清单中的<application>标签中应该修复它:

<activity android:name="com.google.android.gms.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 
+1

谢谢!两周后,我终于有广告:) – JrodManU 2014-09-04 23:18:01