AdMob的 - 没有广告展示 [英] Admob - no ad to show

查看:158
本文介绍了AdMob的 - 没有广告展示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好 我尝试做一些示例程序显示在Android手机的广告,我尝试在2.2版的仿真测试 在code一切似乎是美好的,但AdListener调试器说:

  

响应消息是零或空;
  onFailedToReceiveAd(无广告展示)。

有没有办法为它是我的错?有没有人遇到同样的问题? 继承人的code 清单:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.AdTest
安卓版code =1
机器人:VERSIONNAME =1.0>
<应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
    <活动机器人:名称=。ADTEST
              机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
<! -  AdMobActivity定义 - >
<活动机器人:名称=com.google.ads.AdActivity
机器人:configChanges =定位|键盘| keyboardHidden/>
< /用途>
<使用-SDK安卓的minSdkVersion =7>< /使用的SDK>
<! -  AdMob的SDK需要Internet权限 - >
<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_NETWORK_STATE/>
 

布局XML

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID /主
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
>
<的TextView
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=@字符串/你好
/>
< / LinearLayout中>
 

和活动code

 包com.AdTest;
进口com.google.ads *。
进口com.google.ads.AdRequest.Error code;
进口android.app.Activity;
进口android.os.Bundle;
进口android.util.Log;
进口android.widget.LinearLayout;

公共类ADTEST扩展活动实现AdListener {
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
  super.onCreate(savedInstanceState);
  的setContentView(R.layout.main);
  的LinearLayout布局=(的LinearLayout)findViewById(R.id.main);
   AD浏览报AD浏览报=新的AD浏览报(这一点,AdSize.BANNER,anonymouse);
   //单元ID是正确的,我改变了它的目的,而粘贴在这里
    adView.setAdListener(本);
    layout.addView(AD浏览报);
    AdRequest请求=新AdRequest();
    adView.loadAd(要求);
  }

 公共无效onFailedToReceiveAd(AD浏览报AD浏览报)
    {
        Log.d(AdListener,onFailedToReceiveAd);
    }

    公共无效onFailedToReceiveRefreshedAd(AD浏览报AD浏览报)
    {
        Log.d(AdListener,onFailedToReceiveRefreshedAd);
    }

    公共无效onReceiveAd(AD浏览报AD浏览报)
    {
        Log.d(AdListener,onReceiveAd);
    }

    公共无效onReceiveRefreshedAd(AD浏览报AD浏览报)
    {
        Log.d(AdListener,onReceiveRefreshedAd);
    }

    @覆盖
    公共无效onDismissScreen(广告为arg0){
        // TODO自动生成方法存根

    }

    @覆盖
    公共无效onFailedToReceiveAd(广告为arg0,错误code ARG1){
          Log.d(AdListener,onFailedToReceiveAD);

    }

    @覆盖
    公共无效onLeaveApplication(广告为arg0){
        // TODO自动生成方法存根

    }

    @覆盖
    公共无效于presentScreen(广告为arg0){
        // TODO自动生成方法存根

    }

    @覆盖
    公共无效onReceiveAd(广告为arg0){
         Log.d(AdListener,接收成功地);

    }
}
 

解决方案

我实现AdListener我的活动,并将其设置为监听AD浏览,然后添加以下

 公共无效onFailedToReceiveAd(广告为arg0,错误code ARG1)
{
    Log.d(AdMob的,无法接受的广告请求一个新的......。+ ARG1);
    arg0.stopLoading();
    arg0.loadAd(新AdRequest());

}
 

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:

Response message is zero or null;
onFailedToReceiveAd( No ad to show).

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 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");

    }
}

解决方案

I implemented AdListener on my Activity and set it as the AdView listener, then added the following

    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());

}

这篇关于AdMob的 - 没有广告展示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆