选择自定义铃声
选择自定义铃声
/** * 选择自定义铃声 */ 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()); } } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~