Android Question [Solved] How to mute the sound of ads using this code?

Pendrush

Well-Known Member
Licensed User
Longtime User
You may try something like this:
B4X:
'Dim MobileAds As MobileAds
'MobileAds.Initialize
Dim volume As Float = 0.5
Dim jo As JavaObject
jo.InitializeStatic("com.google.android.gms.ads.MobileAds")
jo.RunMethod("setAppVolume", Array(volume))

or

B4X:
Dim mute As Boolean = True
Dim jo As JavaObject
jo.InitializeStatic("com.google.android.gms.ads.MobileAds")
jo.RunMethod("setAppMuted", Array(mute))
 
Last edited:
Upvote 0

asales

Expert
Licensed User
Longtime User
Thanks. It works, but this code:
B4X:
Dim MobileAds As MobileAds
MobileAds.Initialize
initialize the mobile ads with the "Admob App ID" in the manifest.

There is no problem if I use several RunMethod? I can use like this?
B4X:
jo.RunMethod("initialize", Array(ctxt, "ca-app-pub-3940256099942544~3347511713"))  'Sample ID
jo.RunMethod("setAppVolume", Array(volume))
jo.RunMethod("setAppMuted", Array(mute))
or I can initialize the MobileAds and initialize another JavaObject to set the AppMuted?
B4X:
Dim MobileAds As MobileAds
MobileAds.Initialize

Dim MobileAds2 As JavaObject
MobileAds2.InitializeStatic("com.google.android.gms.ads.MobileAds")
MobileAds2.RunMethod("setAppMuted", Array(True))
 
Last edited:
Upvote 0

asales

Expert
Licensed User
Longtime User
It is a static method so it is not tied to any specific object. Pendrush code is correct.
So, If I put the Admob App ID in the manifest and use this code:
B4X:
jo.InitializeStatic("com.google.android.gms.ads.MobileAds")
I don't need this code:
B4X:
jo.RunMethod("initialize", Array(ctxt, "ca-app-pub-3940256099942544~3347511713"))
Correct?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
I'm a little bit confused. So, my final code will be this (in Starter):
B4X:
Dim MobileAds As MobileAds
MobileAds.Initialize

Dim mute As Boolean = True
Dim jo As JavaObject
jo.InitializeStatic("com.google.android.gms.ads.MobileAds")
jo.RunMethod("setAppMuted", Array(mute))
 
Upvote 0
Top