gpt4 book ai didi

java - 广告未加载

转载 作者:行者123 更新时间:2023-12-02 05:29:38 27 4
gpt4 key购买 nike

我按照有关插页式广告的谷歌教程进行操作,但每当我尝试显示广告时,它都不会加载。我尝试使用 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>

Android启动器

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;
}
}

最佳答案

如果您遇到此错误:

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

然后在 <application> 中添加此 Activity 声明你的 list 中的标签应该修复它:

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

关于java - 广告未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25675571/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com