英文:
Getting Received log message: <Google:HTML> Incorrect native ad response. Click actions were not properly specified.witht error code 0
问题
以下是您提供的内容的翻译部分:
我正试图实现原生广告。在模拟器上尝试测试单元和真实单元时,我得到了错误代码0和3。在检查日志时,我发现了以下语句。
Received log message: <Google:HTML> Incorrect native ad response. Click actions were not properly specified
Ad failed to load : 0
当我使用真实的广告单元时,会出现错误代码0。
我正试图将这个原生广告填充到一个FrameLayout中。
以下是我XML文件中的代码片段:
<LinearLayout
android:id="@+id/adLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="vertical">
<FrameLayout
android:id="@+id/nativeAdArea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
以下是我的Java代码片段。
FrameLayout nativeAdArea;
nativeAdArea = findViewById(R.id.nativeAdArea);
private void showNativeBanner() {
AdLoader adLoader = new AdLoader.Builder(this, getResources().getString(R.string.admob_native_mainactivity))
.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
@Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
Log.e("nativead", "loaded");
// 展示广告。
nativeAdArea.setVisibility(View.VISIBLE);
UnifiedNativeAdView adView = (UnifiedNativeAdView) getLayoutInflater()
.inflate(R.layout.layout_homepage_nativead, null);
// 这个方法将文本、图片和原生广告等填充到广告视图中。
mUnifiedNativeAd = populateUnifiedNativeAdView(unifiedNativeAd, adView);
nativeAdArea.removeAllViews();
nativeAdArea.addView(adView);
}
})
.withAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
mUnifiedNativeAd.setOnPaidEventListener(new OnPaidEventListener() {
@Override
public void onPaidEvent(AdValue adValue) {
Bundle params = new Bundle();
params.putString("valuemicros", String.valueOf(adValue.getValueMicros()));
params.putString("currency", adValue.getCurrencyCode());
params.putString("precision", String.valueOf(adValue.getPrecisionType()));
params.putString("adunitid", getResources().getString(R.string.admob_native_mainactivity));
params.putString("network", Objects.requireNonNull(mUnifiedNativeAd.getResponseInfo()).getMediationAdapterClassName());
AnalyticsManager.logEvent("paid_ad_impression", params);
}
});
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.e("nativead", "failedtoload" + errorCode);
// 通过日志、更改UI等方式处理失败。
nativeAdArea.setVisibility(View.GONE);
// getSmaatoNativeAd();
}
@Override
public void onAdClicked() {
if (mFirebaseAnalytics == null) {
mFirebaseAnalytics = FirebaseAnalytics.getInstance(NewMainActivity.this);
}
Bundle adClickAnalyticsbundle = new Bundle();
adClickAnalyticsbundle.putString("app_version", BuildConfig.VERSION_NAME);
adClickAnalyticsbundle.putString("type", "native");
adClickAnalyticsbundle.putString("ad_unit_name", "homepage_lower_native");
mFirebaseAnalytics.logEvent("clicked_ad", adClickAnalyticsbundle);
Bundle abTestBundle = new Bundle();
abTestBundle.putString("app_version", BuildConfig.VERSION_NAME);
abTestBundle.putString("type", "native");
mFirebaseAnalytics.logEvent("native_vs_adaptive", abTestBundle);
}
})
.withNativeAdOptions(new NativeAdOptions.Builder()
// 可以在NativeAdOptions.Builder类中使用的方法在此处用于指定单个选项设置。
.build())
.build();
AdRequest adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build();
runOnUiThread(() -> {
adLoader.loadAd(adRequest);
});
}
英文:
I am trying to implement native ads. I am getting error code 0 and 3 on both test units and real units when trying on emulator. While checking the logs I found the following statement.
Received log message: <Google:HTML> Incorrect native ad response. Click actions were not properly specified
Ad failed to load : 0
Error code 0 is coming when I am using real Ad units.
I am trying to populate this native ad inside a FrameLayout.
Below is a code snippet from my xml file:
<LinearLayout
android:id="@+id/adLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="vertical">
<FrameLayout
android:id="@+id/nativeAdArea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
Here's my java code snippet.
FrameLayout nativeAdArea;
nativeAdArea = findViewById(R.id.nativeAdArea);
private void showNativeBanner() {
AdLoader adLoader = new AdLoader.Builder(this, getResources().getString(R.string.admob_native_mainactivity))
.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
@Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
Log.e("nativead", "loaded");
// Show the ad.
nativeAdArea.setVisibility(View.VISIBLE);
UnifiedNativeAdView adView = (UnifiedNativeAdView) getLayoutInflater()
.inflate(R.layout.layout_homepage_nativead, null);
// This method sets the text, images and the native ad, etc into the ad
// view.
mUnifiedNativeAd = populateUnifiedNativeAdView(unifiedNativeAd, adView);
nativeAdArea.removeAllViews();
nativeAdArea.addView(adView);
}
})
.withAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
mUnifiedNativeAd.setOnPaidEventListener(new OnPaidEventListener() {
@Override
public void onPaidEvent(AdValue adValue) {
Bundle params = new Bundle();
params.putString("valuemicros", String.valueOf(adValue.getValueMicros()));
params.putString("currency", adValue.getCurrencyCode());
params.putString("precision", String.valueOf(adValue.getPrecisionType()));
params.putString("adunitid", getResources().getString(R.string.admob_native_mainactivity));
params.putString("network", Objects.requireNonNull(mUnifiedNativeAd.getResponseInfo()).getMediationAdapterClassName());
AnalyticsManager.logEvent("paid_ad_impression", params);
}
});
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.e("nativead", "failedtoload" + errorCode);
// Handle the failure by logging, altering the UI, and so on.
nativeAdArea.setVisibility(View.GONE);
// getSmaatoNativeAd();
}
@Override
public void onAdClicked() {
if (mFirebaseAnalytics == null) {
mFirebaseAnalytics = FirebaseAnalytics.getInstance(NewMainActivity.this);
}
Bundle adClickAnalyticsbundle = new Bundle();
adClickAnalyticsbundle.putString("app_version", BuildConfig.VERSION_NAME);
adClickAnalyticsbundle.putString("type", "native");
adClickAnalyticsbundle.putString("ad_unit_name", "homepage_lower_native");
mFirebaseAnalytics.logEvent("clicked_ad", adClickAnalyticsbundle);
Bundle abTestBundle = new Bundle();
abTestBundle.putString("app_version", BuildConfig.VERSION_NAME);
abTestBundle.putString("type", "native");
mFirebaseAnalytics.logEvent("native_vs_adaptive", abTestBundle);
}
})
.withNativeAdOptions(new NativeAdOptions.Builder()
// Methods in the NativeAdOptions.Builder class can be
// used here to specify individual options settings.
.build())
.build();
AdRequest adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build();
runOnUiThread(() -> {
adLoader.loadAd(adRequest);
});
}
```
[![Here's a snapshot of the log][1]][1]
[1]: https://i.stack.imgur.com/f43d9.png
</details>
# 答案1
**得分**: 2
我在模拟器上也遇到了同样的问题,但是当我在真机上尝试相同的代码时,原生广告似乎可以正常工作。
<details>
<summary>英文:</summary>
I also faced same issue on emulator but when I tried same code on real device native ads seems to work perfectly.
</details>
# 答案2
**得分**: 2
我遇到了相同的问题,并在这里找到了另一个正确的答案:https://stackoverflow.com/questions/67355780/flutter-native-admob-ad-failed-to-load-0
您需要在安装了Google Play框架的模拟器上测试您的应用程序。
<details>
<summary>英文:</summary>
I had the same issue and found another correct answer on this: https://stackoverflow.com/questions/67355780/flutter-native-admob-ad-failed-to-load-0
You need to test your app with an emulator that has Google Play framework installed.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论