android - 提取原生广告时出现“广告加载失败:3”的一些原因是什么?
问题描述
我正在尝试为 Google AdMob 原生广告使用原生模板,但我什至无法加载测试广告。我的主要活动如下所示:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
MobileAds.initialize(this) {}
var adLoader: AdLoader = AdLoader.Builder(this, ADMOB_AD_UNIT_ID)
.forUnifiedNativeAd { ad: UnifiedNativeAd ->
var styles: NativeTemplateStyle =
NativeTemplateStyle.Builder().build()
var template: TemplateView = findViewById(R.id.my_template)
template.setStyles(styles)
template.setNativeAd(ad)
}
.withAdListener(object : AdListener() {
override fun onAdFailedToLoad(adError: LoadAdError) {
print("Failed: " + adError.toString())
// Handle the failure by logging, altering the UI, and so on.
}
})
.withNativeAdOptions(
NativeAdOptions.Builder()
// Methods in the NativeAdOptions.Builder class can be
// used here to specify individual options settings.
.build()
)
.build()
adLoader.loadAd(AdRequest.Builder().build());
}
}
虽然我AndroidManifest.xml
看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admobtest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
应用程序 ID 和单元 ID 均来自此示例项目。没有编译错误;看起来 AdMob 记录“广告加载失败:3”。我已经读到这个问题随着时间的推移而得到解决,但这不是我的应用程序/单元 ID,所以它绝对不应该发生。这些 id 适用于上述示例项目,所以我的代码肯定有问题,但我不知道它可能是什么。
解决方案
推荐阅读
- c++ - 这三种创建向量的方式有何不同?
- terraform - 无法为 rds 子网组提供计数和子网 ID
- python - Pymongo:不断创建新的 id
- cmake - 是否可以在 cmake 中获取目标文件名?
- python - 为什么 matplotlib 不显示特定的数学文本
- visual-studio-code - 如何在我的 vscode 扩展中获取最新版本号?
- azure-devops - Azure DevOps 扩展项目名称返回 externalContentHost512
- c# - 将 CustomControl 的可视状态管理器与其样式分开
- python - NumPy 中是否有多个范围?
- oracle - 从员工表中删除行