我遵循關於插頁式廣告的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;
}
}
你已經在谷歌AdMob聯播儀表板創建插頁式廣告單元? – donfuxx 2014-09-04 22:03:09
同時檢查logcat輸出(過濾標籤:廣告)。 Admob會在廣告完成加載時進行日誌記錄,並且還會記錄該事件出錯的情況。 – donfuxx 2014-09-04 22:16:48
「無法找到com.google.android.gms.ads.AdActivity,請確保它在AndroidManifest.xml中聲明」猜猜我沒有做xml權利。 – JrodManU 2014-09-04 22:27:17