Android Question Testing if all sounds are muted

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Can you tell me if there is an easy way to test if all sounds on a device are muted?

Is there a toggle I can set in code to mute and un-mute the device?

Thanks.
 

rleiman

Well-Known Member
Licensed User
Longtime User

Hi,

Thanks for letting me know of Phone.SetMute.

I used it like this:

B4X:
Sub SwMute_CheckedChange (Checked As Boolean)

    If SwMute.Checked = True Then
        LabelMuted.text = "Sound Is On"

        phThePhone.SetMute(phThePhone.VOLUME_ALARM, False)
        phThePhone.SetMute(phThePhone.VOLUME_MUSIC, False)
        phThePhone.SetMute(phThePhone.VOLUME_NOTIFICATION, False)
        phThePhone.SetMute(phThePhone.VOLUME_RING, False)
        phThePhone.SetMute(phThePhone.VOLUME_SYSTEM, False)
        phThePhone.SetMute(phThePhone.VOLUME_VOICE_CALL, False)
       
        kvConfigurationSettings.PutSimple1("Sound Is Muted", 0, "Not Muted")
    Else
        LabelMuted.text = "Muted"
       
        phThePhone.SetMute(phThePhone.VOLUME_ALARM, True)
        phThePhone.SetMute(phThePhone.VOLUME_MUSIC, True)
        phThePhone.SetMute(phThePhone.VOLUME_NOTIFICATION, True)
        phThePhone.SetMute(phThePhone.VOLUME_RING, True)
        phThePhone.SetMute(phThePhone.VOLUME_SYSTEM, True)
        phThePhone.SetMute(phThePhone.VOLUME_VOICE_CALL, True)
       
        kvConfigurationSettings.PutSimple1("Sound Is Muted", 0, "Muted")
    End If
End Sub

but all of the volumes got muted except VOLUME_ALARM and VOLUME_VOICE_CALL.

They stay the same and are not muted. Is this a bug with SetMute ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can make your code shorter:
B4X:
 phThePhone.SetMute(phThePhone.VOLUME_ALARM, SwMute.Checked)
        phThePhone.SetMute(phThePhone.VOLUME_MUSIC,  SwMute.Checked)
        phThePhone.SetMute(phThePhone.VOLUME_NOTIFICATION,  SwMute.Checked)
        phThePhone.SetMute(phThePhone.VOLUME_RING,  SwMute.Checked)
        phThePhone.SetMute(phThePhone.VOLUME_SYSTEM,  SwMute.Checked)
        phThePhone.SetMute(phThePhone.VOLUME_VOICE_CALL,  SwMute.Checked)
... other code here

It is possible that Android doesn't allow you to mute these channels. You can change the ringer mode instead.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User

Hi Erel,

Thanks for the coding sample.

Since it looks like Android won't allow me to mute them, I think I will just set the volumes to 0 and restore them to their original values when the user taps a switch view.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…