/**
* 选择自定义铃声
*/
private void selectCustomSoung() {
String notificationStr = SpUtils.getSettingString(NewsMsgNoticeActivity.this, CUSTOM_SONG_URI, null);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
// 允许用户选择“默认”
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
// 只显示铃声
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
//设置默认通知值
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
// 不显示“沉默”
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
Uri notificationUri;
if (notificationStr != null) {
notificationUri = Uri.parse(notificationStr);
// Put checkmark next to the current ringtone for this contact
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, notificationUri);
} else {
// Otherwise pick default ringtone Uri so that something is selected.
notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// Put checkmark next to the current ringtone for this contact
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, notificationUri);
}
// Launch!
startActivityForResult(intent, customSongRequestCode);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == customSongRequestCode && data != null) {
Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (null == pickedUri) {
//静音
SpUtils.putSettingString(NewsMsgNoticeActivity.this, CUSTOM_SONG_URI, null);
} else {
//获取铃声名称
// String strRingtone = RingtoneManager.getRingtone(NewsMsgNoticeActivity.this, pickedUri).getTitle(NewsMsgNoticeActivity.this);
SpUtils.putSettingString(NewsMsgNoticeActivity.this, CUSTOM_SONG_URI, pickedUri.toString());
}
}
}