Admob - 没有广告要展示

2022-09-03 07:56:07

您好,我尝试制作一些示例程序,在Android手机上显示广告,并尝试在v2.2的模拟器上测试它 代码中的所有内容似乎都很好,但是调试器中的AdListener说:

响应消息为零或空;
onFailedToReceiveAd(没有广告显示)。

有什么办法让它成为我的错吗?有没有人遇到同样的问题?下面是代码清单:

<?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" />

布局 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>

和活动代码

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

    }
}

答案 1

我遇到了同样的问题

onFailedToReceiveAd(没有广告显示)。

由于某些原因,AdMob 似乎没有为我们的应用发送广告内容。即使我处于测试模式,仍然没有广告。

我在 AdMob 上制作自家广告来验证我的申请。这是开发中比测试模式更简单的方法。


答案 2

我在活动上实现了 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());

}

推荐