#if java
import android.os.Bundle;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdRequest;
public Object GetCollapsibleRequest(String placement) {
AdRequest.Builder builder = new AdRequest.Builder();
Bundle extras = new Bundle();
extras.putString("collapsible", placement);
builder.addNetworkExtrasBundle(AdMobAdapter.class, extras);
return builder;
}
#End If
Dim request As AdRequestBuilder = Me.As(JavaObject).RunMethod("GetCollapsibleRequest", Array("bottom"))
BannerAd.LoadAdWithBuilder(request)
If you check this post, you will that I don't get an answer to the problem and I could not fix it.also check this post
Yes, I think that's it. I found this information:Looks like it creates a dialog and adds it to the activity. All pages share the same activity.
I don't found how to close or collapse it automatically and I don't think so is allowed by Google because they are very restricted with the ads now.There is no API to close it.
I'm getting the dreaded "no fill" error right now, so can't test it. You might be able to find the close button and programmatically click it (I'm not sure whether this is allowed by Google or not).
Is there any chance to make it work properly without B4XPages?1. Use B4XPages.
2. Add this to the end of the page:
B4X:#if java import android.os.Bundle; import com.google.ads.mediation.admob.AdMobAdapter; import com.google.android.gms.ads.AdRequest; public Object GetCollapsibleRequest(String placement) { AdRequest.Builder builder = new AdRequest.Builder(); Bundle extras = new Bundle(); extras.putString("collapsible", placement); builder.addNetworkExtrasBundle(AdMobAdapter.class, extras); return builder; } #End If
3.
B4X:Dim request As AdRequestBuilder = Me.As(JavaObject).RunMethod("GetCollapsibleRequest", Array("bottom")) BannerAd.LoadAdWithBuilder(request)
I think it works better with activity instead b4xpages (like I said above).Is there any chance to make it work properly without B4XPages?
I use this code:I think it works better with activity instead b4xpages (like I said above).
But due the problem that still showing after close the page, I gave up with this format.
AdViewCollapsible.Initialize2("AdViewCollapsible","ca-app-pub-3940256099942544/2014213617", AdaptiveSize.Get("native")) ' test colapsable ad
Activity.AddView(AdViewCollapsible, 0, 100%y - AdaptiveSize.Get("height") , AdaptiveSize.Get("width"), AdaptiveSize.Get("height"))
' Dim builder As AdRequestBuilder = Me.As(JavaObject).RunMethod("GetCollapsibleRequestBottom", Null) 'baixo para cima
Dim builder As AdRequestBuilder
builder.Initialize
builder = Me.As(JavaObject).RunMethod("GetCollapsibleRequest", Array("bottom"))
' builder = Me.As(JavaObject).RunMethod("GetCollapsibleRequestBottom", Null)
AdViewCollapsible.LoadAdWithBuilder(builder)
(IllegalArgumentException) java.lang.IllegalArgumentException: Expected receiver of type com.goldtest.Gold.priece.gold.test.main, but got java.lang.Class<com.goldtest.Gold.priece.gold.test.main>
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim AdViewCollapsible As AdView
Type AdSize (Native As Object, Width As Int, Height As Int) 'there is another option using AdsHelper class
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
Activity.Title = "Activity Collapsible Banner"
Dim size As AdSize = GetAdaptiveAdSize
AdViewCollapsible.Initialize2("AdViewCollapsible", "ca-app-pub-3940256099942544/2014213617", size.Native)
Dim jo As JavaObject
jo.InitializeContext
Dim builder As AdRequestBuilder = jo.RunMethod("GetCollapsibleRequest", Array("bottom"))
Activity.AddView(AdViewCollapsible, 0, 100%y - size.Height, size.Width, size.Height)
AdViewCollapsible.LoadAdWithBuilder(builder)
End Sub
Sub Activity_Resume
' Place any code here that needs to run when the activity resumes
AdViewCollapsible.Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
AdViewCollapsible.Pause
End Sub
'Adaptive Banners
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
#If Java
import android.os.Bundle;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdRequest;
public AdRequest.Builder GetCollapsibleRequest(String placement) {
AdRequest.Builder builder = new AdRequest.Builder();
Bundle extras = new Bundle();
extras.putString("collapsible", placement);
builder.addNetworkExtrasBundle(AdMobAdapter.class, extras);
return builder;
}
#End If