[英]Admob live ads not appearing in libgdx application - Failed to load ad: 0
我目前正在使用eclipse luna开发libgdx andriod应用,并尝试通过admob显示横幅广告。
我的应用运行良好,并且没有任何问题地显示了测试横幅广告。
当我将手机作为测试设备来接收实时广告时,我在logcat中收到以下错误消息:
There was a problem getting an ad response. ErrorCode: 0 Failed to load ad: 0
我已经在运行Android 6.0.1版的Galaxy Note 4和Samsung S5上测试了我的应用程序。 两台设备上均没有自定义ROM或广告拦截器,并且测试广告均可在这两台设备上使用。
我按照Google Android指南的一些参考遵循了该实施指南 。
我认为这是问题所在。
通过我的SDK Manager,我安装了Google Play服务修订版39和Google存储库修订版44。
该指南说,请附加位于以下位置的google-play-services_lib:
C:\\ Users \\ ... \\ AppData \\ Local \\ Android \\ sdk \\ extras \\ google \\ google_play_services
但是,该文件不再存在,在遵循了此问题的答案中的信息之后,我找到了google-play-services_lib rev 29并将其添加到可以正常工作的项目库中。 如果SDK Play Manager上的Google Play服务修订版本与我手动添加的修订版本不同,是否有意义?
无论哪种方式,这都不会影响测试广告的效果,但是我不确定,是否错过了可能导致此错误的任何内容?
我也要求Google小组 (Google Mobile Ads SDK开发人员)提供帮助,但没有运气。
我的应用程序单元ID:
广告单元ID:ca-app-pub-3059505755009716 / 4168523587
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'
在build.grandle中的android依赖项中丢失了,刷新后的依赖项仍然没有实时广告。
根据谷歌
“可能是您最近才创建了一个新的广告单元ID,并要求投放实时广告。在这种情况下,可能要花几个小时才能开始投放广告。如果您要接收测试广告,则可以实施。请稍等几个小时,然后看看您是否能够接收实时广告。如果不能,请向我们发送您的广告单元ID,以供我们查询。”
https://groups.google.com/forum/#!category-topic/google-admob-ads-sdk/android/fBe3YL3ffpo
所以等几个小时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.