Admob - no ad to show

好久不见. 提交于 2019-12-23 07:26:08

问题


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

    }
}

回答1:


I have confront the same problem with

onFailedToReceiveAd( No ad to show).

It seems AdMob not sent ad content for our app for some reasons. Even when I in testing mode there's still no ad.

I create my house ad on AdMob to verify my application. It's an easier way in development than testing mode.




回答2:


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

}



回答3:


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:

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.




回答4:


Change the test mode to true. Note that ads will not be displayed until at least 3 access attempts are made for the day.




回答5:


It appears that the latest admob SDK 4.0.4 doesn't display ads on 1.5 devices.

In the emulator it works fine for 1.6+, but not 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.

Also see this link




回答6:


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

In general, admob prints detailed error to log (ID missing, activity missing in manifest etc).




回答7:


I had done the admob integration and that is run on device as well as on emulator.

so, please try below code:

I think you have to remove textview from main.xml

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

try it bro.




回答8:


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:

Add Google Admob in Android Application



来源:https://stackoverflow.com/questions/5350933/admob-no-ad-to-show

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!