Android Question JavaObject : restarting from the ground...

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,

Sorry as it will be a stupid question for many of you. I have decided to learn more seriously how to use JavaObject and choosed a really simple sample : getting the LoudSpeaker state (this because there is an example on developer.android). And you know what ? I am already lost.

Well, if a good fellow around could help me understanding what I should do...

OK, here is the summary :
- seen here that I have to deal with AudioManager
- seen here that the class is "android.media.AudioManager"
- on the same page that I will get a Boolean while calling isSpeakerPhoneOn()

Well, well. So I started really slowly trying to understand, dealing with some sample found here but with no luck.
I have seen that
B4X:
Dim Jo As JavaObject
Jo.InitializeStatic("android.media.AudioManager")
Produces no error. Classy :)

But it becomes difficult for me to understand the way to do. In fact, I wonder if I well understand the way to access the field (I am sorry if it is simple).
B4X:
Dim Jo As JavaObject
Jo.InitializeStatic("android.media.AudioManager")
Log(Jo.GetField("isSpeakerphoneOn"))

If it is stupidly written, I do apologize, but you would have laughed :)

Thanks a lot
 

LucaMs

Expert
Licensed User
Longtime User
From: http://developer.android.com/reference/android/media/AudioManager.html
"Use Context.getSystemService(Context.AUDIO_SERVICE) to get an instance of this class."

and since I don't know how to do it using JavaObject:
B4X:
Sub isSpeakerphoneOn As Boolean

    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    Return r.RunMethod("isSpeakerphoneOn")

End Sub

:D
 
Upvote 0
Top