I've been putting AdMob ads in an otherwise working Android app, following the instructions here. The app has 2 activities. One of them is only reachable from the first. I'm currently adding ads to this second activity. I've tried both creating an AdView
programmatically in the onCreate
method and adding appropriate code to the XML layout file for the Activity. In both cases the activity will exit the second Activity and go to the first as if the back button had been pressed as soon as it recieves an ad (or at least some ad data over the network). If I change the code so as to not make an add request (even if I add the ad programatically but just don't to call loadAd
), or if I turn off my netwrok access then I don't see any ads, but my Activity doesn't exit either. What could be causing this?
I've gone through all the (I believe out of date) steps here, but that doesn't help. Just to be clear in case I did something wrong, I have:
- Downloaded the latest Android and AdMob SDKs, at least as of last Friday.
- Set 'target=android-17' in default.properties (which I had to create in the root of the project, since I couldn't fine) and project.properties (which is what I think the project actually uses).
- Set 'android:minSdkVersion="3"' in AndroidManifest.xml.
- Added the library to the project (by placing GoogleAdMobAdsSdk-6.2.1.jar in a libs directory in the project root).
- Added a
com.google.ads.AdActivity
copied from here to AndroidManifest.xml. - Added permission to AndroidManifest.xml, again copied from the same place.
- Copied both code and XML tags (and attributes) from here and added them to my project (replacing MY_AD_UNIT_ID with my publisher ID), although I also broke out the request in code to make the emulator a test device.
- Added an attrs.xml with ad styles. I'm fairly certain this is obsolete advice, but I did it anyway. I used the one from this question, although I changed
com.admob.android.ads.AdView
tocom.google.ads
.
The next thing I think you'll want to know if you try to help me is what LogCat says. Not much:
09-02 14:33:34.861: I/Ads(12839): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"msid":"com.Package.Name","hl":"en","bas_off":0,"simulator":1,"preqs":0,"slotname":"a150cbaa53d9d3d","js":"afma-sdk-a-v6.2.1","isu":"B3EEABB8EE11C2BE770B684D95219ECB","u_audio":4,"cap":"m,a","cipa":0,"u_sd":1.5,"net":"ed","u_h":533,"oar":0,"session_id":"4834854664722735718","seq_num":"1","app_name":"1.android.com.Package.Name","bas_on":0,"kw":[],"u_w":320,"gnt":3,"adtest":"on","format":"320x50_mb","carrier":"310260","ad_pos":{"visible":0,"width":0,"height":0,"x":0,"y":0},"ptime":0});</script></head><body></body></html>
09-02 14:33:35.111: D/dalvikvm(12839): GC freed 8784 objects / 437720 bytes in 64ms
09-02 14:33:37.101: I/Ads(12839): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?msid=com.Package.Name&hl=en&bas_off=0&preqs=0&js=afma-sdk-a-v6.2.1&isu=B3EEABB8EE11C2BE770B684D95219ECB&u_audio=4&cap=m%2Ca&cipa=0&u_sd=1.5&net=ed&u_h=533&oar=0&session_id=4834854664722735718&seq_num=1&app_name=1.android.com.Package.Name&bas_on=0&kw&u_w=320&gnt=3&adtest=on&format=320x50_mb&carrier=310260&ptime=0&u_so=p&output=html®ion=mobile_app&u_tz=0&client_sdk=1&ex=1&slotname=a14e8f77524dde8&kw_type=broad&gsb=3g&caps=interactiveVideo_th_autoplay_mediation_sdkAdmobApiForAds_di&jsv=41" type: "admob" afmaNotifyDt: "null" useWebViewLoadUrl: "false">
09-02 14:33:37.111: I/Ads(12839): Request scenario: Online server request.
09-02 14:33:38.061: I/jdwp(12861): received file descriptor 10 from ADB
09-02 14:33:38.091: D/ddm-heap(12861): Got feature list request
EDIT: I don't think it will be very useful, but at the request of suleman khan here is my current XML
<com.google.ads.AdView android:layout_width="wrap_content"
android:layout_height="wrap_content" ads:adUnitId="a150cbaa53d9d3d"
ads:adSize="SMART_BANNER" android:id="@+id/adView" ads:refreshInterval="60"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true" />
I"ve tried many variations of this, with no success.