Android Question Audio State ?

SoyEli

Active Member
Licensed User
Longtime User
Hello:

Is it possible to get the audio state ?
Like: Bluetooth, loudspeaker, earphone(the part that you put up to the ear) etc...

I know you can use this to set the state:

Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
Log("Audio Target = " & r.Target)
Dim mode As Int
If Value Then mode = 0 Else mode = 2
r.RunMethod2("setMode", mode, "java.lang.int")

But I need to GET the state.

Thank you:
SoyEli
 

SoyEli

Active Member
Licensed User
Longtime User
Thank you:

I tried, all I get is "0", No change if I switch to speaker, Bluetooth or earphone.
Code:
[Public Sub GetAudioMode() As Int]
[Dim r As Reflector]
[Dim mode As Int]
[ r.Target = r.GetContext]
[ r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")]
[ mode = r.RunMethod("getMode")]
[ Log("Audio mode = " & mode)]
[ Return mode]
[End Sub]

If I use: [r.RunMethod2("setMode", mode, "java.lang.int")]
then I get 0 or 2.
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
Thank you:

Is "audiomanager" library the exact name ?, looked for about 45 min, unable to find where to download.
I found audio library closest to name.
searching for a specific library is not as easy as it sounds on this forum.

Thank you for the help.
SoyEli

:)
 
Last edited:
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
Hello:

Can anybody please tell me the page to download the library "AudioManager"

Thank you :)
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
Thank you:
will try to find a example on how to use it.
the example I found: Does not work, I always get "0":

Code:
[Public Sub GetAudioMode() As Int]
[Dim r As Reflector]
[Dim mode As Int]
[ r.Target = r.GetContext]
[ r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")]
[ mode = r.RunMethod("getMode")]
[ Log("Audio mode = " & mode)]
[ Return mode]
[End Sub]
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you should write code in the post like this
[ code ] (without the spaces here)
Public Sub GetAudioMode() As Int
Dim r As Reflector
Dim mode As Int
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
mode = r.RunMethod("getMode")
Log("Audio mode = " & mode)
Return mode
End Sub
[/code]

I don't think that there is any other API to get the audio mode.
 
Upvote 0
Top