我目前正在使用eclipse luna開發libgdx andriod應用程序,並嘗試通過admob顯示橫幅廣告。Admob實時廣告未出現在libgdx應用程序中 - 無法加載廣告:0
我的應用運行良好,顯示測試橫幅廣告沒有問題。
當我刪除我的手機作爲測試設備,以獲得即時廣告,我得到這個錯誤的logcat:
There was a problem getting an ad response. ErrorCode: 0 Failed to load ad: 0
我測試過我的應用程序上的Galaxy Note 4和三星S5既運行Android版本6.0.1。在任一設備上都沒有自定義ROM或廣告攔截器,並且這兩個測試廣告都能正常工作。
我遵循this指南的實施與google's android guide一些參考。
這裏就是我認爲這個問題是..
通過我的SDK管理器我有谷歌Play服務,修訂39和安裝谷歌庫修訂44。
資料說附上谷歌播放-services_lib位於:
C:\用戶\ ... \應用程序數據\本地\ Android的\ SDK \演員\谷歌\ google_play_services
但是該文件不再存在,在根據this回答問題後,我發現google-play-services_lib rev 29並將其添加到我的項目庫中。如果SDK管理器上的Google Play服務修訂版與我手動添加的版本不同,那麼修訂版是否會有所修改?
無論哪種方式,這應該無關緊要,因爲測試廣告的工作,但我不知道,我錯過了任何可能導致此錯誤?
我也向google groups(Google移動廣告SDK開發人員)尋求幫助,但沒有運氣。
我的應用程序單元ID:
廣告單元ID:爲ca-app-PUB-4168523587分之3059505755009716
AP ID:爲ca-app-PUB-3059505755009716〜2178916381
我的Java實現(AndriodLauncher.java):
public class AndroidLauncher extends AndroidApplication implements AdsController {
private static final String BANNER_AD_UNIT_ID = "ca-app-pub-3059505755009716/4168523587";
// ca-app-pub-3059505755009716/8048823189
// ca-app-pub-3059505755009716/4168523587
AdView bannerAd;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// Create a gameView and a bannerAd AdView
View gameView = initializeForView(new Boot(this), config);
setupAds();
// Define the layout
RelativeLayout layout = new RelativeLayout(this);
layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(bannerAd, params);
setContentView(layout);
}
public void setupAds() {
bannerAd = new AdView(this);
bannerAd.setVisibility(View.GONE);
bannerAd.setBackgroundColor(Color.argb(0, 0, 0, 0)); // black
bannerAd.setAdUnitId(BANNER_AD_UNIT_ID);
bannerAd.setAdSize(AdSize.BANNER);
}
@Override
public void showBannerAd() {
runOnUiThread(new Runnable() {
@Override
public void run() {
bannerAd.setVisibility(View.VISIBLE);
AdRequest.Builder builder = new AdRequest.Builder();
//builder.addTestDevice("9F2779F709CED00E2ADF6123C0D17A4C");
//builder.addTestDevice("ECDD91BD30440E7B3F4DA0E90F1D67A9");
AdRequest ad = builder.build();
bannerAd.loadAd(ad);
}
});
}
@Override
public void hideBannerAd() {
runOnUiThread(new Runnable() {
@Override
public void run() {
bannerAd.setVisibility(View.INVISIBLE);
}
});
}
}
代碼片段showBannerAd()
方法被稱爲:
public Boot(AdsController adsController){
this.adsController = adsController;
}
@Override
public void create() {
//Gdx.app.log(TITLE, "started..");
// Display ads (andriod launch)
adsController.showBannerAd();
setScreen(new Splash());
Timer.schedule(new Task(){
@Override
public void run() {
assets = new Assets();
assets.load();
assets.manager.finishLoading();
Audio.create();
Audio.bgm.play();
Audio.bgm.setLooping(true);
setScreen(new MainMenu());
}
}, 3f);
}
AndriodManifest。XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="25" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name="com.game.AndroidLauncher"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
編輯:注意的行
compile 'com.google.android.gms:play-services-ads:10.0.1'
從Android的依賴失蹤build.grandle內,刷新依賴性仍然沒有活廣告。
我有3天的ap單位ID。我已經發布到您提到的論壇,並被告知我的應用ID根據他們的測試正在製作實時廣告。 – girthquake
嘗試更改廣告:adSize =「BANNER」with ads:adSize =「SMART_BANNER」 – Aryan
我已經使用SMART_BANNER,BANNER和LARGE_BANNER顯示測試廣告的所有選項都沒有問題。當我註釋掉addTestDevice()以獲得實時廣告時,我得到相同的錯誤。 – girthquake