Trouble getting ads to display on android with adMob
I've included the relevant portion in开发者_高级运维 my manifest:
<meta-data android:value="123456789" android:name="ADMOB_PUBLISHER_ID" />
<!-- Track Market installs from AdMob ads -->
<receiver android:name="com.admob.android.ads.analytics.InstallReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" />'
and
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>'
attrs copied right from the example:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.admob.android.ads.AdView">
<attr name="backgroundColor" format="color" />
<attr name="primaryTextColor" format="color" />
<attr name="secondaryTextColor" format="color" />
<attr name="keywords" format="string" />
<attr name="refreshInterval" format="integer" />
</declare-styleable>
</resources>
My layout (Which is a tabs view btw) is a table with it on its own row:
xmlns:app="http://schemas.android.com/apk/res/com.icukansas.lenscalculator"
and
<TableRow>
<!-- Place an AdMob ad at the bottom of the screen. -->
<!-- It has white text on a black background. -->
<com.admob.android.ads.AdView
android:layout_span="4"
android:id="@+id/ad"
app:backgroundColor="#000000"
app:primaryTextColor="#FFFFFF"
app:secondaryTextColor="#CCCCCC"
app:keywords="security"
/>
</TableRow>
I then call:
public class myClass extends Activity implements AdListener{
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.tab_thistab);
AdView ad = (AdView) findViewById(R.id.ad);
ad.setAdListener(this);
Every time I get onFailedToReceiveAd error in the log.
I'm sure its something easy I'm missing :)
I know this is old, but I figured it would be helpful for people trying to put an ad in a tablelayout. I eventually got this to work by including android:stretchColumns="0,1,2,3" in my TableLayout. If your span was something other than 4 you would put the same amount of columns/numbers in stretchColumns as your span.
<TableLayout android:id="@+id/TableLayout01" android:stretchColumns="0,1,2,3" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
Yes You are missing two thing:
1.Most Important :
<meta-data android:value="a14e20856e4ad8f" android:name="ADMOB_PUBLISHER_ID" />
2.Refresh Interval:
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:refreshInterval="30"
/>
Rest looks fine.
You forgot to add the netstate permission in the manifest.
I had the same issue - friggin tabview. Placing it in the main activity instead of the tabs worked perfectly.
hi jason I have solution, may be it will help write this code in your class
AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR, // Android emulator
"5669B77A6042345BC23219DCAC6C15CA",// device id
});
ad = (AdView) findViewById(R.id.ad);
ad.requestFreshAd();
ad.setAdListener(this);
you can get device id in logcat after running application in info tab, search for text.
To get test ads on the emulator use AdManager.setTestDevices... also set listeners
and you will get your device id, paste it , otherwise your previous code is perfect.
I have tried it problem for almost 3 hours already. I follow all google example. Finaly, i figure it out. You can customized the request, then it will work. In my example, I do this in the Activity class:
AdRequest re = new AdRequest();
//re.setTesting(true);
re.setGender(AdRequest.Gender.FEMALE);
adview.loadAd(re);
You can check my example here, I always put my apk, and source code. You can download and try:
Add Google Admob in Android Application
精彩评论