Android Question AdMob - Adaptive Banners

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes.

1:
B4X:
Sub GetAdaptiveAdSize As AdSize
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim AdSize As JavaObject
   Dim width As Int = 100%x / GetDeviceLayoutValues.Scale
   Dim res As AdSize
   res.Native = AdSize.InitializeStatic("com.google.android.gms.ads.AdSize").RunMethod("getCurrentOrientationAnchoredAdaptiveBannerAdSize", Array(ctxt, width))
   Dim jo As JavaObject = res.Native
   res.Width = jo.RunMethod("getWidthInPixels", Array(ctxt))
   res.Height = jo.RunMethod("getHeightInPixels", Array(ctxt))
   Return res
End Sub

2: Add to Process_Globals
B4X:
Type AdSize (Native As Object, Width As Int, Height As Int)

3. Usage:
B4X:
Dim size As AdSize = GetAdaptiveAdSize
adview1.Initialize2("ad", "ca-app-pub-126753333333/948333333", size.Native)
Activity.AddView(adview1, 0, 0,  size.Width, size.Height)
 
Upvote 0

asales

Expert
Licensed User
Longtime User
3. Usage:
B4X:
Dim size As AdSize = GetAdaptiveAdSize
adview1.Initialize2("ad", "ca-app-pub-126753333333/948333333", size.Native)
Activity.AddView(adview1, 0, 0,  size.Width, size.Height)
And this line:
B4X:
adview1.LoadAd
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
4. Minversion of Artifact: 18.3.0
Solution: Start B4ASDKManager and download all recommended items.
 
Upvote 0

joaomoraes83

Member
Licensed User
I installed the recommendations but problem persists.
I am using the ready to use SDK.
Is the adaptive banner only available for V9.5 +?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I installed the recommendations but problem persists.
Which problem? I don´t see you posted it in this thread!?
If you have a problem then i suggest to start a new thread for your Issue, post all relevant code, and the FULL ERROR you got (as TEXT).
 
Upvote 0
Top