Android Question Phone.GetMute? (not Phone.SetMute)

JackKirk

Well-Known Member
Licensed User
Longtime User
I would like to be able to determine a voice channels mute state before I change it with Phone.SetMute(...) - so I can restore the mute state later.

I've looked high and low on the forums without success.

Something like Phone.GetMute(...) would be ideal.

Failing this, is there another way to do it?

Thanks in advance...
 

Johan Schoeman

Expert
Licensed User
Longtime User
Check the last posting here:

http://stackoverflow.com/questions/11985448/how-to-check-if-phone-is-mute-vibrate-or-loud-in-android

It can most probably be implemented with a bit of inline Java code.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

Thanks for the prompt response.

Your suggestion looks like it is in the right area, but unfortunately for me is still out of reach.

I have been using B4A for about 4 weeks and this is my first app. While I have many years of vb6/5/4/... experience I have absolutely no Java.

If anyone could show me how to implement with a bit of inline Java code I would be most appreciative.

Thanks again...
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Try the attached project. You need to have the JavaObject library enabled in the B4A project's Libraries Manager tab. It will print the state of the ringer (a boolean value) to the B4A log.

Note that the following line has been added to the B4A project's manifest file:

B4X:
AddPermission("android.permission.READ_PHONE_STATE")
 

Attachments

  • b4aJackKirk.zip
    6.9 KB · Views: 305
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

Once again thank you for your prompt response - I'm starting to get really impressed with this community and how it enhances B4A.

I was able to install and run the project you supplied above without any problems.

I now have a clear understanding of how to incorporate small bits of Java - although the Java itself is still essentially double-Dutch (does that translate?).

I did manage to modify your project (including the Java) to return the ringer state (0=mute, 1=vibrate, 2=sound) - I love to tinker!

This led me to re-explore the Phone library and the user level sound mode settings:

o I had been using the Phone library's SetMute method to change the mute state of the VOLUME_MUSIC voice channel to ON before using it.

o It turns out that the Phone library also has GetRingerMode and SetRingerMode methods with associated ringer state constants of RINGER_SILENT, RINGER_VIBRATE and RINGER_NORMAL which appear to render our Java exercises redundant (although still a very valuable learning experience).

o These methods and constants seem to pretty much exactly match the user level sound mode settings I have on my device (Samsung Galaxy S5) via [Settings] > [Sounds and notifications] > [Sound mode] > [Sound/Vibrate/Mute].

o In these user level sound mode settings it would appear that the [Media] channel equates to the B4A VOLUME_MUSIC channel.

o Here is where it starts to get a bit confusing:

(1) If I manually set the sound mode to [Mute] it does not impact the [Media]/VOLUME_MUSIC channel - it is still audible.

(2) Would this be common to all Android devices? If so does it mean I don't need to worry about using Phone.SetMute to ensure the VOLUME_MUSIC channel is not muted before using it?

(3) Or should I play safe and use Phone.GetRinger/SetRinger to manage the sound mode mute state before using the VOLUME_MUSIC channel?

(4) It would appear that Phone.SetMute is doing things the user can not manually do - what is its value?

Any comments would be appreciated and thanks again...
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

Useful, I've decided to play safe in my app for now and manage Phone.GetRinger/SetRinger around my TTS utterances.

I'm still interested in knowing what the real value of Phone.SetMute is.

Cheers...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…