Android AdMob 示例

Android AdMob example(Android AdMob 示例)
本文介绍了Android AdMob 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 在这里.在图片中,广告上写着AdMob Test Android Web Ad",但是当我运行代码时,我有时会看到一个实际的广告,有时什么也看不到.为什么?

I downloaded example code of an Android project featuring AdMob ads from here. In the picture, the ad says "AdMob Test Android Web Ad", but when I run the code, I sometimes see an actual ad and sometimes see nothing. Why?

推荐答案

确保在模拟器上启用了测试模式.似乎链接中的代码没有启用它的测试模式.

Ensure that test mode is enabled on emulator. Seems like the code in the link does not have it's test mode enable.

启动应用程序后,广告不会立即运行.需要几秒钟(最多 10 秒,具体取决于您的网络速度)才能接收来自 Admob 的广告.

Ads do not run immediately after launching the application. It would take a couple of seconds(up to 10secs, depending on your network speed) before being able to receive an advertisement from Admob.

在你的 onCreate() 中尝试这样的操作.

Try something like this in your onCreate().

    adView = new AdView(this, AdSize.BANNER, "a9876sf98dfg");        
    RelativeLayout layout = (RelativeLayout)findViewById(R.id.ad);        
    layout.addView(adView);
    AdRequest request = new AdRequest();
    request.setTesting(false);
    adView.loadAd(request);

编辑(来自评论):按照 edumobile.org/android/android-development/admob-manager 上的说明操作,但将android:id="@+id/linearLayout" 行添加到 main 的 LinearLayout 部分.xml.

EDIT (from the comments): Follow the instructions on edumobile.org/android/android-development/admob-manager, but add the line "android:id="@+id/linearLayout" to the LinearLayout part of main.xml.

这篇关于Android AdMob 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)