Android Question Any news about Native Ads Advanced?

asales

Well-Known Member
Licensed User
Hi @Erel
I have several Native Ads Express in my apps and the existing units will stop serving ads on March 1, 2018 (https://developers.google.com/admob/android/native-express).

The new Native Ads Advanced is available now and I can create this Ads (I think the information in page "Native is currently in a closed beta with a limited group of publishers" is out of date), but I don't have a option in FirebaseAdmob library to use it, only NativeExpressAd.

native2.jpg


Any news about when we can get the updated FirebaseAdmob library?

Thanks in advance for your attention about this issue.
 

asales

Well-Known Member
Licensed User
Weird, because to me they it appears (see image below).

I can create the native ads but I can use they in B4A.

But I saw the answer of the SDK team: the native express is discontinued but they don't have a timeline to release the native advanced. Bad news, but thanks for your effort!
native3.jpg
 

Multiverse app

Active Member
Licensed User
I have been waiting to get native advanced ads for months now. Banner ads look ugly and have very less RPM. let's hope Google makes it available fast.
 

Douglas Farias

Expert
Licensed User
I will add it to FirebaseAdMob once it is publicly available.
Hi @Erel .
Sorry to reopen a old thread.

but you have a plan to add advanced native ads to firebase admob lib?
if yes can you talk when?(day)?

we have some apps with normal native ads and on day 01 of month 02 (01/02) it will no more works.
google contacted me and talked about, change with urgency native ads to advanced native ads (the normal native ads will show only a blank page).

thx
 
Last edited:

DonManfred

Expert
Licensed User
but you have a plan to add advanced native ads to firebase admob lib?
He already answered this. He´ll add them if the are publicity available.

They are still in Beta! So i guess nothing will happen and he can´t answer when as it is not known when they are public available.
 

DonManfred

Expert
Licensed User

asales

Well-Known Member
Licensed User
This is a deadline letter that Google sent to me.

The problem is that I use the native express ads in several places that not is recomended to use a banner.

admob010318.jpg
 

Erel

Administrator
Staff member
Licensed User

This code will help you get started:
B4X:
Sub LoadNativeAd
   Dim AdUnitId As String = "ca-app-pub-3940256099942544/2247696110"
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim builder As JavaObject
   builder.InitializeNewInstance("com.google.android.gms.ads.AdLoader.Builder", Array(ctxt, AdUnitId))
   Dim OnContentAdLoadedListener As Object = builder.CreateEventFromUI("com/google/android/gms/ads/formats/NativeContentAd.OnContentAdLoadedListener".Replace("/", "."), _
       "ContentAdLoaded", Null)
   builder.RunMethod("forContentAd", Array(OnContentAdLoadedListener))
   
   Dim Listener As JavaObject
   Listener.InitializeNewInstance(Application.PackageName & ".main$MyAdListener", Array("NativeAd"))  'change 'main' with the current activity module name
   builder.RunMethod("withAdListener", Array(Listener))
   Dim AdLoader As JavaObject = builder.RunMethod("build", Null)
   Dim AdRequestBuilder As JavaObject
   AdRequestBuilder.InitializeNewInstance("com/google/android/gms/ads/AdRequest.Builder".Replace("/", "."), Null)
   AdLoader.RunMethod("loadAd", Array(AdRequestBuilder.RunMethod("build", Null)))
   Wait For ContentAdLoaded_Event (MethodName As String, Args() As Object)
   
   Log("ContentAdLoaded_Event")
   Dim NativeContentAd As JavaObject = Args(0)
   Log(NativeContentAd.RunMethod("getHeadline", Null))
   Dim NativeContentAdView As JavaObject
   NativeContentAdView.InitializeNewInstance("com/google/android/gms/ads/formats/NativeContentAdView".Replace("/", "."), _
       Array(ctxt))
   Dim pNativeAdView As Panel = NativeContentAdView
   Dim content As Panel
   content.Initialize("")
   pNativeAdView.AddView(content, 0, 0, 300dip, 300dip)
   Dim lbl As Label
   lbl.Initialize("")
   lbl.Text = NativeContentAd.RunMethod("getHeadline", Null)
   content.AddView(lbl, 10dip, 10dip, 300dip, 50dip)
   NativeContentAdView.RunMethod("setHeadlineView", Array(lbl))
   Dim lbl2 As Label
   lbl2.Initialize("")
   lbl2.Text = NativeContentAd.RunMethod("getBody", Null)
   content.AddView(lbl2, 10dip, 60dip, 300dip, 50dip)
   NativeContentAdView.RunMethod("setBodyView", Array(lbl2))
   Dim logo As JavaObject = NativeContentAd.RunMethod("getLogo", Null)
   If logo.IsInitialized Then
       Log("adding logo")
       Dim logoView As Panel
       logoView.Initialize("")
       logoView.Background = logo.RunMethod("getDrawable", Null)
       content.AddView(logoView, 200dip, 0, 100dip, 100dip)
       NativeContentAdView.RunMethod("setLogoView", Array(logoView))
   End If
   Dim images As List = NativeContentAd.RunMethod("getImages", Null)
   If images.IsInitialized And images.Size > 0 Then
       Log("adding image")
       Dim imgView As Panel
       imgView.Initialize("")
       Dim image As JavaObject = images.Get(0)
       imgView.Background = image.RunMethod("getDrawable", Null)
       content.AddView(imgView, 200dip, 100dip, 100dip, 100dip)
       NativeContentAdView.RunMethod("setImageView", Array(imgView))
   End If
   NativeContentAdView.RunMethod("setNativeAd", Array(NativeContentAd))
   Activity.AddView(pNativeAdView, 0, 0, 100%x, 200dip)
End Sub

Sub NativeAd_FailedToReceiveAd (ErrorCode As String)
   Log("NativeAd_FailedToReceiveAd: " & ErrorCode)
End Sub

Sub NativeAd_AdOpened
   Log("NativeAd_AdOpened")
End Sub

#if Java
public static class MyAdListener extends com.google.android.gms.ads.AdListener {
   
   String eventName;
   public MyAdListener(String s) {
       eventName = s.toLowerCase(BA.cul);
   }
   @Override
   public void onAdClosed() {
       processBA.raiseEventFromDifferentThread(null, null, 0, eventName + "_adclosed", false, null);
   }
   @Override
   public void onAdFailedToLoad(int arg0) {
       processBA.raiseEventFromDifferentThread(null, null, 0, eventName + "_failedtoreceivead", false, new Object[] {String.valueOf(arg0)});
   }
   @Override
   public void onAdLeftApplication() {
       processBA.raiseEventFromDifferentThread(null, null, 0, eventName + "_adleftapplication", false, null);
   }
   @Override
   public void onAdOpened() {
       processBA.raiseEventFromDifferentThread(null, null, 0, eventName + "_adopened", false, null);
   }
   @Override
   public void onAdLoaded() {
       processBA.raiseEventFromDifferentThread(null, null, 0, eventName + "_receivead", false, null);
   }
}
#End If
This is not complete. You can see all the available resources here: https://developers.google.com/android/reference/com/google/android/gms/ads/formats/NativeContentAd
Each resource should be set to a view and you should then call NativeContentAdView setXXXView.
NativeContentAdView: https://developers.google.com/andro...e/android/gms/ads/formats/NativeContentAdView

Note that it will be easier to create the layout with the designer and load it with content.LoadLayout.
 
Last edited:

asales

Well-Known Member
Licensed User
Thank you very much, @Erel.

I'm try several modifications in this code.
One thing that I want to do is to show 2 native ads in same activity.
So I created a sub "LoadNativeAd2" and I call LoadNativeAd (top = 0) and LoadNativeAd2 (top = 50%y), but only last sub that I call is showing.
LoadNativeAd (first)
LoadNativeAd2 (last)
or
LoadNativeAd2 (first)
LoadNativeAd (last)

don't matter

What could be happening?
How I can show 2 ads in same activity?

Thanks in advance for any tip.
 

Douglas Farias

Expert
Licensed User

This code will help you get started:
B4X:
Sub LoadNativeAd
   Dim AdUnitId As String = "ca-app-pub-3940256099942544/2247696110"
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim builder As JavaObject
   builder.InitializeNewInstance("com.google.android.gms.ads.AdLoader.Builder", Array(ctxt, AdUnitId))
   Dim OnContentAdLoadedListener As Object = builder.CreateEventFromUI("com/google/android/gms/ads/formats/NativeContentAd.OnContentAdLoadedListener".Replace("/", "."), _
       "ContentAdLoaded", Null)
   builder.RunMethod("forContentAd", Array(OnContentAdLoadedListener))
 
   Dim AdLoader As JavaObject = builder.RunMethod("build", Null)
   Dim AdRequestBuilder As JavaObject
   AdRequestBuilder.InitializeNewInstance("com/google/android/gms/ads/AdRequest.Builder".Replace("/", "."), Null)
   AdLoader.RunMethod("loadAd", Array(AdRequestBuilder.RunMethod("build", Null)))
   Wait For ContentAdLoaded_Event (MethodName As String, Args() As Object)
 
   Log("ContentAdLoaded_Event")
   Dim NativeContentAd As JavaObject = Args(0)
   Log(NativeContentAd.RunMethod("getHeadline", Null))
   Dim NativeContentAdView As JavaObject
   NativeContentAdView.InitializeNewInstance("com/google/android/gms/ads/formats/NativeContentAdView".Replace("/", "."), _
       Array(ctxt))
   Dim pNativeAdView As Panel = NativeContentAdView
   Dim content As Panel
   content.Initialize("")
   pNativeAdView.AddView(content, 0, 0, 300dip, 300dip)
   Dim lbl As Label
   lbl.Initialize("")
   lbl.Text = NativeContentAd.RunMethod("getHeadline", Null)
   content.AddView(lbl, 10dip, 10dip, 300dip, 50dip)
   NativeContentAdView.RunMethod("setHeadlineView", Array(lbl))
   Dim lbl2 As Label
   lbl2.Initialize("")
   lbl2.Text = NativeContentAd.RunMethod("getBody", Null)
   content.AddView(lbl2, 10dip, 60dip, 300dip, 50dip)
   NativeContentAdView.RunMethod("setBodyView", Array(lbl2))
   Dim logo As JavaObject = NativeContentAd.RunMethod("getLogo", Null)
   If logo.IsInitialized Then
       Log("adding logo")
       Dim logoView As Panel
       logoView.Initialize("")
       logoView.Background = logo.RunMethod("getDrawable", Null)
       content.AddView(logoView, 200dip, 0, 100dip, 100dip)
       NativeContentAdView.RunMethod("setLogoView", Array(logoView))
   End If
   Dim images As List = NativeContentAd.RunMethod("getImages", Null)
   If images.IsInitialized And images.Size > 0 Then
       Log("adding image")
       Dim imgView As Panel
       imgView.Initialize("")
       imgView.Background = logo.RunMethod("getDrawable", Null)
       content.AddView(imgView, 200dip, 100dip, 100dip, 100dip)
       NativeContentAdView.RunMethod("setImageView", Array(imgView))
   End If
   NativeContentAdView.RunMethod("setNativeAd", Array(NativeContentAd))
   Activity.AddView(pNativeAdView, 0, 0, 100%x, 200dip)
End Sub
This is not complete. You can see all the available resources here: https://developers.google.com/android/reference/com/google/android/gms/ads/formats/NativeContentAd
Each resource should be set to a view and you should then call NativeContentAdView setXXXView.
NativeContentAdView: https://developers.google.com/andro...e/android/gms/ads/formats/NativeContentAdView

Note that it will be easier to create the layout with the designer and load it with content.LoadLayout.
Hi erel.

i m tested your code today, and this give some crash

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
entra aqui?
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
ContentAdLoaded_Event
Duploxxis Delivery
adding image
Error occurred on line: 2530 (Main)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
at anywheresoftware.b4a.BA$1.run(BA.java:325)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
** Activity (main) Pause, UserClosed = true **
how can i fix this pls?
i see u made a if to check if contains image, the code enter on this if but i dont know give crash when will get the image
 

Douglas Farias

Expert
Licensed User
Run it in debug mode. Which line raises the error (post the code itself)?
sorry to dont post the line.
the error on debug mode is on this line

B4X:
imgView.Background = logo.RunMethod("getDrawable", Null)

here is the log
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
entra aqui?
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
ContentAdLoaded_Event
Duploxxis Delivery
adding image
Error occurred on line: 2530 (Main)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
at anywheresoftware.b4a.BA$1.run(BA.java:325)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
** Activity (main) Pause, UserClosed = true **
Note: Duploxxis Delivery on log its a ad name. (it is working getting ads title)
the problem is the image only
 
Top