Cannot get admob ad activity showing, help needed please

mistermentality

Active Member
Licensed User
Longtime User
[Solved] Cannot get admob ad activity showing, help needed please

I am new to admob, and having followed the tutorial and edited my apps manifest manually and then setting it to read only I install my app but I don't get anything, no advert not even a blank banner area on screen and am unsure why.

I first tried using the example code but no joy so tried amending it in case for some reason the activity view was being hidden so now the code reads...

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main.bal")
   AdView1.Initialize("Ad", "my publisher id goes here")
        Activity.AddView(AdView1, 0dip, 0dip, 320dip, 50dip)
        AdView1.Visible = True
   Adview1.BringToFront
        AdView1.LoadAd
End Sub

I get no error messages and the manifest has the correct entries added, shouldn't I get at least a black banner area or have I made some stupid mistake?

The manifest reads....

B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="TxtSpK.com"
      android:versionCode="1"
      android:versionName=""
     android:installLocation="internalOnly">
      <uses-sdk android:minSdkVersion="4" />
      <supports-screens
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:anyDensity="true"/>
    <application android:icon="@drawable/icon" android:label="TxtSpK">
       
        <activity android:windowSoftInputMode="stateHidden" android:launchMode="singleTop" android:name=".main"
                  android:label="TxtSpK" android:screenOrientation="unspecified">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

              <!-- *** For AdMob: manually added *** -->
              <activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

On the admob site my package url is set to https://market.android.com/details?id=TxtSpK.com which will be the page for the app when uploaded, its package name is TxtSpK.com but it is not on the market yet as still testing it, could this stop it working bearing in mind that it shows no error messages in LogCat nor any banners?

Any help appreciated :)

Dave

Edit: I have checked with the logs and it does not show an error about not loading an ad so does not appear to be trying. It is puzzling
 
Last edited:

mistermentality

Active Member
Licensed User
Longtime User
Thank you for the reply :)

I haven't amended the code to run it specifically for the emulator but have run it as is on both my phone and the emulator and do not even get a blank ad area on screen nor do the logs show it is trying to load an advert and then failing, it is as if the code is just not starting the view for some reason.

The steps I took are, in summary...
1. Register and get admob code and the sdk
2. Download the admob library for b4a and copy both this (with xml file) and admobs own jar (which the b4a library file has an xml file for) with the appropriate xmls (and having renamed the admob jar as the guide says to do) to my b4a libraries path so the two libraries and xml files are present.
3. Add code to my app to show an ad, with my publisher id inserted in the right place.
4. Adjust the manifest file and make it read only.
5. compile and run (with message saying it is using the read only manifest but no errors)


In a worst case scenario, for example if something was wrong somehow that I was unaware of, shouldn't there at least still be a space on screen where the ad would be if it were called?

Am really puzzled by it not working.

Dave
 
Last edited:
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
I am checking the unfiltered logs, I will search the forums and see how to use the test ads and try adapting it for the emulator and report back.

Dave
 
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
I have trimmed my code and adjusted it to this....

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main.bal")
   AdView1.Initialize("Ad", "removed_id") 'publisher id that you received from AdMob.
    Activity.AddView(AdView1, 0dip, 0dip, 320dip, 50dip) 'previously the height was 48dip. Now it is 50dip.
   AdView1.LoadAd 'loads an ad
End Sub

and the emulator log shows this line....

Could not find com.google.ads.AdActivity, please make sure it is registered in AndroidManifest.xml.

but my manifest is still the same as before and has not been over written. Any idea where I have gone wrong?

Dave
 
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
I have re read the tutorial many times and cannot see any part I have missed, so as far as I am aware yes as I did not get this error before just no ads.

I have the b4a admob library and the admob sdk library ticked in the libraries section and I added the appropriate text to the manifest which is the same as it was in my first post so I think I haven't missed anything, I don't see anything I have forgotten to add but obviously I have missed something or wouldn't get the error in the emulator.

I have even re downloaded the libraries in case I had a faulty file download but the libraries and definitions seem fine.

Dave

Edit: in the tutorial it just says "1. Add a reference to AdMob and GoogleAdMobAdsSdk libraries." is this just ticking the boxes in the libraries tabs as have done that?
 
Last edited:
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
Your XML is wrong. The new activity should be declared inside the Application node.

I feel a complete idiot having spent two days trying to figure it out, you are correct. I simply moved the added xml code up to inside the application node and it worked fine in the emulator first time.

Sorry I wasted your time but thank you very much for showing me my error, I know nothing about xml and didn't even realise the mistake.

Dave
 
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
It worked on the emulator but not in real use, when trying on phone I get these errors...

B4X:
To get test ads on this device, call adRequest.addTestDevice("FA40555997AFD8E5307857AC0289429E");

adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1,"slotname":"a14e208a2658508","u_w":320,"msid":"TxtSpK.com","js":"afma-sdk-a-v4.1.0","isu":"FA40555997AFD8E5307857AC0289429E","format":"320x50_mb","net":"wi","app_name":"1.android.TxtSpK.com","hl":"en","u_h":480,"testing":1,"u_audio":1,"u_so":"p"});</script></head><body></body></html>

Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=0&u_sd=1&slotname=a14e208a2658508&u_w=320&msid=TxtSpK.com&js=afma-sdk-a-v4.1.0&isu=FA40555997AFD8E5307857AC0289429E&format=320x50_mb&net=wi&app_name=1.android.TxtSpK.com&hl=en&u_h=480&testing=1&u_audio=1&u_so=p&output=html&region=mobile_app&u_tz=-60&ex=1&client_sdk=1", "afmaNotifyDt": "null">

IOException connecting to ad url.

java.net.ConnectException: r.admob.com/127.0.0.1:80 - Connection refused

onFailedToReceiveAd(A network error occurred.)

So I still have to figure it out for the actual device but does work in the emulator :)

Edit: I think I know the cause and can't correct it. I have ad block addresses in my hosts file in /etc probably from when I tried an adblock app last year but uninstalled it, however it seems the hosts file is still filled with addresses to block so not an admob problem and not one I can sort as cannot delete hosts file even with rootexplorer but I do know the cause now and have checked and admob does receive the requests so it is working :)

Dave
 
Last edited:
Upvote 0
Top