Android Question [Solved] Google AdMob: Restricted ad serving - Modified ad code: Resizing Ad Frames

danijel

Active Member
Licensed User
I got an email from google today that there is a problem with one of my applications
and I need to check Policy center.

This is my Policy centre:

admob.png


I am using basic code for ad placement.
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 - height, 100%x, height)
I haven't changed my code for months and it's not clear to me what they are saying:
Modified ad code: Resizing Ad Frames?

Did anyone have any similar problems and know what the problem is exactly and how to solve it?
Thank you
 

danijel

Active Member
Licensed User
Thx @asales for your tip.

I have 2 banners and 1 interstitial ad.
I am trying adaptive ads now. I hope that will help.
 

danijel

Active Member
Licensed User
I have solved my problem so I have a moral responsibility to share a solution with all of you.
Although it clearly states that the issue is "Modified ad code: Resizing Ad Frames" this is not the case.
The problem was that in some cases I inadvertently partially or completely cover banner ad with a popup menu/dialog.
When I wanted to show the popup dialog I had to set ad.visible=false first.
While it may seem logical now if you try to google the problem, you will find a lot of confused developers who are also not clear about what they did wrong, although they do not resize the ad.
Hope to save someone a few days of life. 😇
 

danijel

Active Member
Licensed User
Hang on.... If I show an interstitial, this covers up the banner ad, so do I need to set the banner ad to not visible when showing an interstitial?
I do not think it is necessary in that case.
I think the most important thing is that the advertisement should be clickable when it is visible.
 

ilan

Expert
Licensed User
i also got this warning few days ago but i really see that the ad is not showing full size even though i use the same code as you posted.

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, 0dip, 100%x, height)
1598214807329.png


as you can see the banner is not showing full size. it happens on my Galaxy S8. what could be the reason?
if i check the height like this:

B4X:
Log("height: " & Adview1.Height)
this is what i get:

height: 175
if i connect the designer to the phone i see a scale of 3.5. so 175/3.5=50 so the hight is 50dip that ok but the result is not ok.

i also tried on Pixel 3 (Emulator) and i get the same result. The banner is not showing full size.
 

Pendrush

Well-Known Member
Licensed User
Use this code. It's better and will resize banner to proper dimension.
 

ilan

Expert
Licensed User
Use this code. It's better and will resize banner to proper dimension.
thanx a lot i will try it out. (btw if this is the proper way then maybe erel should update the Admob thread)
 

ilan

Expert
Licensed User
Use this code. It's better and will resize banner to proper dimension.
thanx again, now the ads are viewing correctly!
 

Pendrush

Well-Known Member
Licensed User
If you want to use smart banner, then this code should work:
B4X:
BannerAd.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", BannerAd.SIZE_SMART_BANNER)
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
Activity.AddView(BannerAd, 0dip, 100%y - AdMobHeight, 100%x, AdMobHeight)
I have used this code for years without any problem.
Source of your problem is described here:
 

skaliwag

Member
Licensed User
I can confirm that the original Smart Size Banner code as listed in Post #1 will now be flagged by Admob as being against policy.
Changing to the code in Post #13, then resubmitting in Admob (they do not appear to re-check unless you tell them to), will solve the problem.
Be aware that this code does give noticeably larger size ads on high resolution, small screen devices.
 
Top