Android Question [CLOSED] Set the volume using Reflection (or JavaObject) ?

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hi,

I am diverting the sound while connected to a bluetooth headset using the SetEarPhone code that Erel previously provided. But after having sent True to SetEarPhone, the volume is very low.

I have tried to find the currently used channel without success. I have tried to force it to be the Music channel to be able to set it using the Phone library, without more luck.

Please, is it possible to use Reflection or JavaObject to use adjustVolume ?
Many thanks
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hi Erel,
Damn, I was not aware this could depend on the API (adjustVolume is available since API1 referring to developer.android).

Let's say API 19 if possible. I do thank you a lot
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Thanks a lot Erel. So please, don't spend much time on this. I'll have to find another workaround :)

EDIT : Below is the solution, I've found. I previously forgot to enable the phone's speaker. Leaving it there for others like me

B4X:
#Region Sends the audio to the phone and not the headset without disconnection
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    Dim mode As Int
    If Value Then mode = 2 Else mode = 0
    r.RunMethod2("setMode", mode, "java.lang.int")
#End Region

#Region Activates the phone's loud speaker
      ' r.Target = r.GetContext
      ' r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
      r.RunMethod2("setSpeakerphoneOn",Value,"java.lang.boolean")
      ' SP ON : Value=True
#End Region
 
Last edited:
Upvote 0
Top