转载请注明出处!!!
1.调用系统铃声设置的Intent,界面上会弹出选择铃声的对话框。
//用于选择铃声后作相应的判断标记 private static final int REQUEST_CODE_PICK_RINGTONE = 1; //保存铃声的Uri的字符串形式 private Uri mRingtoneUri = null;
private void doPickRingtone() { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); // Allow user to pick 'Default' intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,"设置铃声"); // Show only ringtones intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE); // Don't show 'Silent' intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); Uri ringtoneUri; if (mRingtoneUri != null) { ringtoneUri = mRingtoneUri; // intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI,Uri.parse(mRingtoneUri)); } else { // Otherwise pick default ringtone Uri so that something is // selected. ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); } // Put checkmark next to the current ringtone for this contact intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,ringtoneUri); // Launch! // startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE); startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE); }
2.选择铃声之后作相应的处理,可以存储到数据库。@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { try { Uri pickedUri =data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); mRingtoneUri = pickedUri; RingtoneManager.setActualDefaultRingtoneUri(MainActivity.this,RingtoneManager.TYPE_RINGTONE, pickedUri); Log.i("pickedUri", mRingtoneUri.toString() + ""); } catch (Exception e) { e.printStackTrace(); } //得到我们选择的铃声 // // 将我们选择的铃声设置成为默认 // RingtoneManager.setActualDefaultRingtoneUri(MainActivity.this,RingtoneManager.TYPE_RINGTONE, pickedUri); // //Uri pickedUri_two = RingtoneManager.setActualDefaultRingtoneUri(MainActivity.this,RingtoneManager.TYPE_ALARM, pickedUri); // RingtoneManager.setActualDefaultRingtoneUri(MainActivity.this,RingtoneManager.TYPE_NOTIFICATION, pickedUri); }