0

I'm trying to change the Notification Ringtone from within my app. So far I can get the Notification Ringtones to show, and then select one of them, but it's not changing it. This is what I'm using so far:

SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
        Uri notification = Uri.parse(settings.getString("timerSound", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString()));

        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Alert Tone");
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, notification);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);     
        startActivityForResult(intent, 5);
RVZ
  • 13
  • 6
  • You need to override onActivityResult and set the selected ringtone as a notification ringtone. – kalyan pvs Mar 21 '14 at 11:09
  • May be this link is helpful to you http://stackoverflow.com/questions/1271777/how-to-set-ringtone-in-android-from-my-activity – Sanket Shah Mar 21 '14 at 11:10

1 Answers1

0

You can change notification ringtone as following code

//new ringtone uri
Uri nuri = Uri.parse("");

//change notification
RingtoneManager.setActualDefaultRingtoneUri(this,RingtoneManager.TYPE_NOTIFICATION, nuri);

if u want to change ringtone sound you can do using following code

    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
for (int volumeType : (new int[] { AudioManager.STREAM_SYSTEM,
    AudioManager.STREAM_RING,AudioManager.STREAM_NOTIFICATION,AudioManager.STREAM_ALARM })) {
        int maxVolume = audio.getStreamMaxVolume(volumeType);
        audio.setStreamVolume(volumeType, maxVolume,
                AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE);
        audio.setStreamMute(volumeType, false);
        audio.setVibrateSetting(volumeType, AudioManager.VIBRATE_SETTING_ON);

thank you

asmalindi
  • 49
  • 8