What I want to do:
To set my ringtone to incoming SMS
even though there is another one in the SMS app
.
What I tried:
In SMS reciever
, I set volume of STREAM_NOTIFICATION to 0
and than tried to play my ringtone as media via MediaPlayer
.
So basically something like this:
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
MediaPlayer mp = MediaPlayer.create(context, notifUri);
mp.start();
int duration = mp.getDuration() + 3000; //Margin
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
}
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, beforOverrideNotifVol, 0);
What happened:
My custom ringtone played but immediately after this, the sms-app
sound rang too.
I tried to add some more sleep to the thread (to let the sms-app play on background) but it just waits for the volume to restore and then plays its ringtone.
At first I tried this:
RingtoneManager.setActualDefaultRingtoneUri(...)
But it doesn't override the app-setting, it only overrides notification sounds when the ringtone is chosen in the sms-app.