Reputation: 5144
I am writing an app that has a feature to temporarily override the system default ringtone with another custom ringtone when the user turn the app on, and restore to the default ringtone when the user turn it off. Meanwhile, the user can change the default ringtone in Settings, or in other app, but as long as my app is running, those changes has no effect until the user turn my app off.
I cannot do it like this
RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, toneUri);
Because it means changing the ringtone itself, not overriding it with another ringtone. Of course I can remember the system ringtone when the app is turned on, and change it back to that ringtone when it is turned off. However, using this approach, any changes made by the user (while my app is still running) in changing the system ringtone will be discarded when my app is turned off, because it will then automatically revert to the previously-remembered ringtone. will make my custom ringtone immediately not in effect anymore
So otherwise how can this be done?
Upvotes: 1
Views: 379
Reputation: 2408
I think you're on the right track with remembering the "old" ringtone and restoring it when your app is finished. The problem, as stated, is what happens when the user changes their ringtone while your app is running.
There are a couple of approaches you could take to avoid this:
In the last case, you should be able to deal with the change, according to the functionality of your app.
Your update raises another question though: are you sure the user wants you to forcibly override their ringtone, even when they change it? If you are, then that's fine, but it's something you need to bear in mind.
Upvotes: 1