I want to give the user access to change the notification ringtone. This "is" through the application settings and NOT. I tried the following code. It shows a ringtone picker, but "it does not install the selected one." I know this has been published a lot of time. What am I doing wrong?
private void setRington() { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); Uri soundFile = 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, soundFile); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); startActivityForResult(intent, 5); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == 5) { Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); Log.i("Speak", "I picked this ringtone " + uri); if (uri != null) { RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, uri); } } }
sam
source share