Android Question Problem with AdView

Massy

Member
Licensed User
Longtime User
Hi all, I'm trying to implement AdMob in my apps, I followed all the instructions in this post: http://www.b4x.com/android/forum/threads/admob-tutorial-add-ads-to-your-application.7300/
but when I add the line: "Dim AdView1 As AdView" I always get this error: Unknown type AdView...
I added the google-play-services.jar file in the Libraries folder and also the GoogleMaps library but still I get that error...
I read a lot of posts about this problem in the forum but couldn't find anything of any help....
Anyone as any idea of what could I be doing wrong?
Thanks a lot for your help
Massy
 

Douglas Farias

Expert
Licensed User
Longtime User
have on the manifest
B4X:
'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

)
'End of AdMob

and in the main
B4X:
#AdditionalRes: C:\android-sdk-windows\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

?
 
Upvote 0

Massy

Member
Licensed User
Longtime User
have on the manifest
B4X:
'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

)
'End of AdMob

and in the main
B4X:
#AdditionalRes: C:\android-sdk-windows\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

?

I have them... but my address for AdditionalRes is: D:\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

as I have the sdk in D: in a folder named Android...
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
can show yout manifest?

and what version is google-play-services <
and what min and target sdk u is using on manifast
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
i m use on the main
B4X:
    #AdditionalRes: C:\b4a-dev\socialapi\googleplus\sdk\res, com.google.android.gms

B4X:
Sub Globals
  Private Adbox As AdView
End Sub


Sub Activity_Create(FirstTime As Boolean)
    Adbox.Initialize2("Ad", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx" , Adbox.SIZE_SMART_BANNER )
    Dim height As Int
    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
    If 100%x > 100%y Then height = 32dip Else height = 50dip
    Else
    height = 90dip
    End If
    Activity.AddView(Adbox, 0dip, 100%y - height, 100%x, height)
      Adbox.LoadAd

my manifest
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")


AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

)


and the admob is checked on the libs >>> ?
 
Upvote 0

Massy

Member
Licensed User
Longtime User
This is what I have in my manifest:

'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

)

'End of AdMob


I don't know how to see what version is google-play-services... could you tell me?
 
Upvote 0

Massy

Member
Licensed User
Longtime User
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
you need the latest google play lib

here
download_1.png





select google play services and update
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
but what version
rev 18 ?

and what your jdk on configure path

my
C:\Program Files (x86)\Java\jdk1.8.0\bin\javac.exe
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
try update you
android sdk use 18 or 19
later change in yout path

and later change the
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19"/>
on manifest
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
lasst try
you is using my code to load the ad?
B4X:
Adbox.Initialize2("Ad", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx" , Adbox.SIZE_SMART_BANNER )

post your code here

sub globals

and firsttime
 
Upvote 0

Massy

Member
Licensed User
Longtime User
lasst try
you is using my code to load the ad?
B4X:
Adbox.Initialize2("Ad", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx" , Adbox.SIZE_SMART_BANNER )

post your code here

sub globals

and firsttime

I'm using the code of the example:

AdView1.Initialize("Ad", "ca-app-pub-xxxxxxxxxxx/xxxxxxxxx") '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



I have this in the Project Attributes:
#AdditionalRes: D:\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms


this in Sub Globals:
Dim AdView1 As AdView

this in Activity_Create:
AdView1.Initialize("Ad", "ca-app-pub-xxxxxxxxxxx/xxxxxxxxx") '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

and all these:

Sub Activity_Resume
AdView1.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
AdView1.Pause
End Sub


Sub Ad_FailedToReceiveAd (ErrorCode As String)
Log("failed: " & ErrorCode)
End Sub
Sub Ad_ReceiveAd
Log("received")
End Sub
Sub Ad_AdScreenDismissed
Log("screen dismissed")
End Sub
 
Upvote 0
Top