Play ringtone at maximum volume even when phone is muted - android

I'd like to develop an application that will play the ringtone at its maximum volume, no matter the user's setting (just how Find My Device works).
This is my code snippet:
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Ringtone ringtoneManager = RingtoneManager.getRingtone(this, ringtone);
ringtoneManager.play();
But couldn't be able to find anything regarding the case I mentioned above. Thank you.

Related

Ringtone not playing on certain Samsung devices with Android 11

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.

How to play the default caller tune sound....?

I am making a calling app and while the user is waiting for the call to connect, I want to play the default sound which is played when we call someone and wait for the correspondent to pick up.
You have to implement RingtoneManager for play default ringtone of system, have look
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Ringtone ringtone = RingtoneManager.getRingtone(this,uri);
ringtone.play();
Hope it will help you!!
It is not possible as such.
You are talking about the ringing tone, also called ringback tone sometimes. It is not generated by the Android system, but the switching system, so you don't have access to it from the API.
To include that sound in your app, you have to include an asset for that sound (mp3).

Android RingtoneManager wont work in API 23 and above.

I have been trying to get the system's default notification sound to play using RingtoneManager. The code works fine until API 22 but just stops working beyond that.
This is how I am doing it,
Uri notificationTone = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notificationTone);
r.play();
What am I missing ? Any help would be appreciated.
it's permission issue in >22, you need to request permission at runtime,
you can checked here

android how to know ringtone length

I'm working on a sample code same as http://developer.android.com/guide/topics/media, I'm successfully playing the ringtone, but I want to know the length of the ringtone(in sec) or atleast a notification after end of the ringtone, so that i have to do some other task after playing the ringtone.
Thanks
nehatha
Put it in a MediaPlayer. You dont have to play it just .prepare() it. Then you can ask MediaPlayer about the duration.

How do I retrieve files or audio files programmatically from the device?

I want to know how to get the ringtone,audio files in the device and I want set them as alarm. How to do it?
I am working in the code to set the alarm and I want to know how to retreive audio or ringtones from the device.
Read the docs on RingtoneManager and Ringtone
RingtoneManager
Ringtone

Categories

Resources