java Admob - 没有可显示的广告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5350933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Admob - no ad to show
提问by gisel
Hello I try to make some example program showing ads on Android phone, and I try to test it on Emulator of v2.2 Everything in code seems to be fine, but AdListener in debugger says that:
您好,我尝试制作一些在 Android 手机上显示广告的示例程序,并尝试在 v2.2 的模拟器上对其进行测试 代码中的所有内容似乎都很好,但是调试器中的 AdListener 说:
Response message is zero or null;
onFailedToReceiveAd( No ad to show).
响应消息为零或空;
onFailedToReceiveAd(无广告显示)。
Is there any way for it to be my fault? Did anyone encounter same problem? Heres the code Manifest:
有什么办法可以归咎于我吗?有没有人遇到同样的问题?下面是代码清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AdTest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AdTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- AdMobActivity definition -->
<activity android:name="com.google.ads.AdActivity"
android:configChanges="orientation|keyboard|keyboardHidden" />
</application>
<uses-sdk android:minSdkVersion="7"></uses-sdk>
<!-- AdMob SDK requires Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Layout xml
布局xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
and Activity code
和活动代码
package com.AdTest;
import com.google.ads.*;
import com.google.ads.AdRequest.ErrorCode;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
public class AdTest extends Activity implements AdListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
AdView adView = new AdView(this, AdSize.BANNER, "anonymouse");
// Unit ID is correct, I changed it on purpose while pasting here
adView.setAdListener(this);
layout.addView(adView);
AdRequest request= new AdRequest();
adView.loadAd(request);
}
public void onFailedToReceiveAd(AdView adView)
{
Log.d("AdListener", "onFailedToReceiveAd");
}
public void onFailedToReceiveRefreshedAd(AdView adView)
{
Log.d("AdListener", "onFailedToReceiveRefreshedAd");
}
public void onReceiveAd(AdView adView)
{
Log.d("AdListener", "onReceiveAd");
}
public void onReceiveRefreshedAd(AdView adView)
{
Log.d("AdListener", "onReceiveRefreshedAd");
}
@Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
Log.d("AdListener", "onFailedToReceiveAD");
}
@Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onReceiveAd(Ad arg0) {
Log.d("AdListener", "Received succesfully");
}
}
回答by Matrix Bai
I have confront the same problem with
我遇到了同样的问题
onFailedToReceiveAd( No ad to show).
onFailedToReceiveAd(无广告显示)。
It seems AdMob not sent ad content for our app for some reasons. Even when I in testing mode there's still no ad.
由于某些原因,AdMob 似乎没有为我们的应用发送广告内容。即使我处于测试模式,仍然没有广告。
I create my house ad on AdMob to verify my application. It's an easier way in development than testing mode.
我在 AdMob 上制作了自家广告以验证我的申请。这是一种比测试模式更简单的开发方式。
回答by gid
I implemented AdListener on my Activity and set it as the AdView listener, then added the following
我在我的 Activity 上实现了 AdListener 并将其设置为 AdView 侦听器,然后添加了以下内容
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1)
{
Log.d("AdMob", "Failed to receive an Ad. Requesting a new one..." + arg1);
arg0.stopLoading();
arg0.loadAd(new AdRequest());
}
回答by John Oleynik
Change the test mode to true. Note that ads will not be displayed until at least 3 access attempts are made for the day.
将测试模式更改为 true。请注意,在当天至少进行 3 次访问尝试后,才会显示广告。
回答by Jonathan
It appears that the latest admob SDK 4.0.4 doesn't display ads on 1.5 devices.
最新的 admob SDK 4.0.4 似乎不会在 1.5 设备上显示广告。
In the emulator it works fine for 1.6+, but not 1.5.
在模拟器中,它适用于 1.6+,但不适用于 1.5。
I think its from the new cross-over advertising with AdSense. As far as I can tell the SDK now wraps a webview as the visual component of the view so it can publish the different kinds of ads. A close look at the log shows WebView.multitouch enabled - as 1.5 doesn't support multitouch (for us developers in Java) due to Apple throwing its toys out of the pram and having a dummyspit (I understand they believe only they are allowed to use two fingers at once..) and perhaps enabling multitouch on the webview causes an internal exception and the view never gets created, and thus cannot receive the HTML reply from the admob http server.
我认为它来自与 AdSense 的新交叉广告。据我所知,SDK 现在包装了一个 webview 作为视图的可视组件,因此它可以发布不同类型的广告。仔细查看日志显示 WebView.multitouch 已启用 - 因为 1.5 不支持多点触控(对于我们 Java 开发人员),因为 Apple 将其玩具从婴儿车中扔出并有一个 dummyspit(我知道他们相信只有他们被允许一次使用两个手指..) 并且可能在 webview 上启用多点触控会导致内部异常并且视图永远不会被创建,因此无法从 admob http 服务器接收 HTML 回复。
Also see this link
另请参阅此链接
回答by Hong Ning
I had the same problem too. So I changed the code to set the test mode true, then the Admob test ad started to show on the emulator. Try this in your OnCreate() method:
我也有同样的问题。于是我修改了代码,将测试模式设置为true,然后Admob测试广告就开始在模拟器上显示了。在你的 OnCreate() 方法中试试这个:
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
AdView adView = new AdView(this, AdSize.BANNER, "anonymouse");
// Unit ID is correct, I changed it on purpose while pasting here
adView.setAdListener(this);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
If you run this on a real device and still no ad to show, then I guess it might have something to do with Admob fill rate.
如果您在真实设备上运行它并且仍然没有显示广告,那么我想这可能与 Admob 填充率有关。
回答by Sulthan
1/ get the latest SDK version
2/ try admob demo with your publisher id
3/ try it in test mode (this should work always)
4/ try to add some sample house ads (shown when there is no other ad available)
5/ try to change your keywords
1/ 获取最新的 SDK 版本
2/ 尝试使用您的发布商 ID 的 admob 演示
3/ 在测试模式下尝试(这应该始终有效)
4/ 尝试添加一些示例自家广告(在没有其他可用广告时显示)
5/尝试更改您的关键字
In general, admob prints detailed error to log (ID missing, activity missing in manifest etc).
一般来说,admob 会打印详细的错误记录(ID 丢失、清单中的活动丢失等)。
回答by Bipin Vayalu
I had done the admob integration and that is run on device as well as on emulator.
我已经完成了 admob 集成,它在设备和模拟器上运行。
so, please try below code:
所以,请尝试以下代码:
I think you have to remove textview from main.xml
我认为你必须从 main.xml 中删除 textview
and also try this:
也试试这个:
1) Create new app on in your admob a/c 2) then simply replace the id of previous app by new one
1) 在您的 admob a/c 中创建新应用程序 2) 然后简单地用新应用程序替换之前应用程序的 ID
try it bro.
试试吧兄弟
回答by James
I also get this problem. You can try to customized the request, before loading. Like this:
我也遇到这个问题。您可以在加载之前尝试自定义请求。像这样:
AdRequest re = new AdRequest();
//re.setTesting(true);
re.setGender(AdRequest.Gender.FEMALE);
adview.loadAd(re);
I put my example, apk file and source code here, you can try:
我把我的例子,apk文件和源代码放在这里,你可以试试: