Android Question How detect if admob mediaview is a video or a image?

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.
i m using the @Erel code posted here.
https://www.b4x.com/android/forum/t...ds-advanced-with-mediaview.96873/#post-611090

this show a video OR a image....
how can i know if is a video or a image via code? i dont know if
getVideoController is the best way to detect this.

what i want to make is, detect if is a video, if is a video i will put this 100% on the nativeads size. if it is a image i need to get the size of the image and load a image with a correct size inside the nativead panel

another way to know if is a video or a image after loaded into the mediaview?

thx
 

Douglas Farias

Expert
Licensed User
Longtime User
hi. sorry i dont understand your english, i tryed use google tradutor but is incomprensive :( .
i have tryed this code, but when the mediaview is image i get a crash on this line
B4X:
Dim vid As JavaObject = NativeUnifiedAd.RunMethod("getVideoController", Null)

there is no way to get the video control if there is no video.

i think the best way is detect on media view, detect if is a image or a video, but i really dont know how to make this via java object
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
@asales

I updated the code in the post.
It checks if there is a video, if don't has a video, check for image.

Logger connected to: ce0916093b5e551d04
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (principal) Create, isFirst = true **
** Activity (principal) Resume **
ContentAdLoaded_Event
Gestão Profissional Venda
Error occurred on line: 249 (principal)
java.lang.RuntimeException: Method: getVideoController not found in: com.google.android.gms.ads.formats.NativeContentAdView
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
at teste.consulta.placa.principal$ResumableSub_LoadNativeAd.resume(principal.java:732)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$1.run(BA.java:330)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (principal) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**


the error is on this line
B4X:
Dim vid As JavaObject = NativeContentAdView.RunMethod("getVideoController", Null)
 
Last edited:
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
I don't know why. This code works for me.

Did you try with Native Ads Unified and don't with Native Content?
https://developers.google.com/admob/android/native-unified

and use the Native Advanced Video test ad?
ca-app-pub-3940256099942544/1044960115
i m using native content, this code from erel.
https://www.b4x.com/android/forum/threads/any-news-about-native-ads-advanced.88100/#post-562893

i dont found any examples of NativeUnifiedAd on the forum. do you have a complete example to post here?

thx
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Last edited:
Upvote 0
Top