this code does not work properly on my Nokia 7.1, because the banner is cut off (see pictures).
So that it is correctly displayed correctly on the Nokia, I have to change the height to 90dip, is this normal?
B4X:
Adview1.Initialize2("Ad", "xxxxxxxx", AdView1.SIZE_SMART_BANNER)
Dim height As Int
If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
'phones
If 100%x > 100%y Then height = 32dip Else height = 50dip
Else
'tablets
height = 90dip
End If
Activity.AddView(AdView1, 0dip, 100%y - (toolbar.height + height), 100%x, height)
It works well for me. I use a panel as base, set its top and height based on the height of the banner (which depends on the device) and then load the layout into this base panel.
In the link it show that the device has Soft Keys.
I got problem detecting screen size because of that.
I solved with ImmersiveMode but it could not be what you want for your app.
Does Nokia have Soft Keys?
Many thanks @Pendrush!
That's exactly what I need.
I have optimized your code a bit.
B4X:
...
Activity.AddView(BannerAd, 0dip, 100%y - GetAddViewHeight , 100%x, GetAddViewHeight)
...
Public Sub GetAddViewHeight As Int
Dim AdMobHeight As Int
If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
Dim ScreenHeightScaled As Float
ScreenHeightScaled = GetDeviceLayoutValues.Height / GetDeviceLayoutValues.Scale
Log("ScreenHeightScaled=" & ScreenHeightScaled)
' Ad height 32dip: device screen height <= 400
' Ad height 50dip: 400 < device screen height <= 720
' Ad height 90dip: device screen height > 720
If ScreenHeightScaled <= 400 Then
AdMobHeight = 32dip
Else if ScreenHeightScaled > 400 And ScreenHeightScaled <= 720 Then
AdMobHeight = 50dip
Else if ScreenHeightScaled > 720 Then
AdMobHeight = 90dip
End If
Else
If 100%y > 100%x Then
'tablets
AdMobHeight = 90dip
Else
AdMobHeight = 50dip
End If
End If
Return AdMobHeight
End Sub
You don't need to change code, you already made a mess with
B4X:
If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
as you will get false result on probably 10%-20% android devices.
Use original code, as original code is in use last two years in app with over 500k active installation, without any problem.
You don't need to change code, you already made a mess with
B4X:
If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
as you will get false result on probably 10%-20% android devices.
Use original code, as original code is in use last two years in app with over 500k active installation, without any problem.
...
Activity.AddView(BannerAd, 0dip, 100%y - GetAddViewHeight , 100%x, GetAddViewHeight)
...
Public Sub GetAddViewHeight As Int
Dim AdMobHeight As Int
Dim ScreenHeightScaled As Float
ScreenHeightScaled = GetDeviceLayoutValues.Height / GetDeviceLayoutValues.Scale
' Ad height 32dip: device screen height <= 400
' Ad height 50dip: 400 < device screen height <= 720
' Ad height 90dip: device screen height > 720
If ScreenHeightScaled <= 400 Then
AdMobHeight = 32dip
Else if ScreenHeightScaled > 400 And ScreenHeightScaled <= 720 Then
AdMobHeight = 50dip
Else if ScreenHeightScaled > 720 Then
AdMobHeight = 90dip
End If
Return AdMobHeight
End Sub
Recent Admob has block some my apps because this problem, because admob banner is cropped!
Code of @Filippo is on code, but our bal file use designer, but on designer we cannot how to get admob height because:
ScreenHeightScaled = GetDeviceLayoutValues.Height / GetDeviceLayoutValues.Scale
can not work on desiger, anyone has idea??