我想授予用户更改通知铃声的权限。它“必须”通过应用程序而不是通过设置。我尝试了以下代码。它显示铃声选择器,但“它没有设置选定的”。我知道它已经发布过很多次了。我究竟做错了什么 ?
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);
}
}
}