2014-09-04 101 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