My code used to successfully silence incoming calls by simply using setRingerMode, but ever since Android Pie, it's just not working anymore. I had tested the built-in DND mode, and it seemed to not be working either. But if that's true, it's working now, but my code still isn't.
Is there something additional necessary for this to work now? Android Pie does keep a separate mode from DND for ring, vibrate, and silence for ringer sounds, but I haven't been able to find figure out why my code isn't working anymore.
Update:
I'm using the following code:
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Update (1-23-19):
My understanding is I can't change the notification channel of another app, like the texting or calling app. Does anybody know any differently?
Related
I'm working on a VoIP app and when a call comes in, the ringtone is not audible on at least a Samsung A20e and a Samsung A71 device running on Android 11. Unfortunately, this info came from a few users who say they experience the issue and the issue doesn't arise on all the phones I have access to, so I'm not able to look in the logs myself.
To get the ringtone URI, the following code is used:
val uri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE)
Then that URI is used on the notification channel:
val attributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build()
notificationChannel.setSound(uri, attributes)
And the URI is used once again in the method setSound of the NotificationCompat.Builder to generate the actual notification.
I tried to reproduce the issue on an emulator and changed the values in setUsage and setContentType a lot, but nothing seemed to have impact. I also reinstalled the app on every change, to make sure a new notification channel would be created.
Then I read somewhere on the internet that ringtones never work on an emulator. However, I do have an emulator on which the ringtone is actually audible, so I'm not so sure that's true, at least not for every configuration.
Lastly I should add that the ringtone also wasn't silent on my original emulator when I added the following line:
RingtoneManager.getRingtone(context, uri).play()
However, I'm not actually able to use that piece of code, since I need to attach the ringtone to a notification (channel).
Does anyone have experience with a same type of issue? Is there a problem with the settings of my notification or the notification channel? Is this just a Samsung issue? I hope someone can help me out.
I'll answer my own question. Turns out the client didn't describe the issue thorough enough and it turned out to be an easily solvable issue when he provided us with more information. The ringtone would be audible when the notification volume of the phone was on and the ringtone volume of the phone was off. However, when the notification volume was off and the ringtone volume was on, the ringtone wouldn't be audible. So the two of those got switched around, which got fixed by replacing AudioAttributes.USAGE_NOTIFICATION with AudioAttributes.USAGE_NOTIFICATION_RINGTONE.
I am revisiting an old question posted (in early 2014 mind) here:
What permissions are needed to programmatically mute a phone call, from a background app?
How to Mute Phone Call Stream (uplink) while calling on Android
How to mute audio speaker in android
How does setMicrophoneMute() work?
For a recent project, I am building an app that can mute an existing call and get an audio recording from the user. I know that audio-recording in-call works, that's no problem (recording only the user mic). Now i can also reduce the volume programmatically, which i did using the code On my Github, Here
Specifically, I am using the AudioManager class to set the volume to 0 and also muting as a backup, but doesn't work.. I am wondering whether this is a Samsung specific issue or not..
mgr.setStreamVolume(stream, progress, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
mgr.adjustVolume(AudioManager.ADJUST_MUTE, AudioManager.FLAG_VIBRATE);
boolean a = mgr.isVolumeFixed();
Log.d("MUTING", "Volume fixed: "+a);
boolean streamMuteStatus = mgr.isStreamMute(stream);
Log.d("MUTING", "Stream Mute Status: "+streamMuteStatus);
I am printing out the boolean variables above for testing purposes, but both print out 'False'.
But the Samsung S5 device is not allowing me to set the volume to 0 at all. This is true even when adjusting the in-call volume using the volume slider.. The slider does not physically move to the leftmost position on the seekbar. See figure below for the leftmost position i can drag to:
Anyone have any ideas about how i can mute the incoming call stream?
I am not able to mute the incoming call ring tone and play my own media file using MediaPlayer class.
So far I have tried the following in my Activity that pops on top of incoming call screen, started using a BroadcastReceiver; Activity shows up but audio doesn't play:
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_RING,true);
am.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
Then I start playing the audio file. The sound plays perfectly in normal mode, so I also set the audio mode to MODE_NORMAL using am.setMode method but no luck.
Is there any way around? I am currently mobile and so I could not post full code. If anyone has done this before, a block of code would be a great help. Moreover, I dug up the documentation for AudioManager class and found setRoute or similar method which looks good but it has been deprecated long ago so I didn't want to implement it.
Does this approach have different reaults when screen is on or off during an incoming call?
I noticed that under Android 4.x setting ring volume to 0 is not possible. If I execute this code and then I go to Settings--> Sound --> Volumes I can see it is set to 1. I
audiomanager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
Do you know why?
I know I could use audiomanager.setRingerMode(RINGER_MODE_SILENT) but annoys me!! because in this case I would have to "remember" if vibration is on or off for activating again sound.
Of course, all this works in other Android versions.
Don't use setStreamMute() as it has weird side-effects with the lifecycle of your process. See the docs:
The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically.
I'm afraid setRingerMode() with either RINGER_SILENT or RINGER_VIBRATE is the way to go, which will have the effect of zero-ing out the stream volume
try setStreamMute instead which is equivalent to setting volume to 0.
What is the difference between calling AudioManager.setRingerMode to calling AudioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, ...)
What does the documentation mean by "Ringer mode"? I'm pretty sure it is the phone ringer mode. Then how does it differ from calling setStreamMute with STREAM_VOICE_CALL?
If it is not the phone ringer mode, then what is it?
Thanks in advance.
I have never used the audio stream on the android platform, however, based on reading the documentation, I think setRingerMode will affect how the phone reacts to incoming calls. For example, AudioManager.setRingerMode(RINGER_MODE_SILENT) will disable vibrations and sound when an incoming call is received.
However, AudioManager.setStreamMute seems to control more than just the audio stream for phone rings.
From the documentation at http://developer.android.com/reference/android/media/AudioManager.html#STREAM_VOICE_CALL
I think that AudioManager.setRingerMode(RINGER_MODE_SILENT) will act the same way as AudioManager.setStreamMute(STREAM_RING, true).
I think the best way to see what the difference is (nd to see if what I am saying is true) would be to write a small program that tests the two features.