调用系统铃声设置

1.调用系统铃声设置的Intent,界面上会弹出选择铃声的对话框。

[java] view plain copy print ?
  1. //用于选择铃声后作相应的判断标记
  2. private static final int REQUEST_CODE_PICK_RINGTONE = 1;
  3. //保存铃声的Uri的字符串形式
  4. private String mRingtoneUri = null;
//用于选择铃声后作相应的判断标记 private static final int REQUEST_CODE_PICK_RINGTONE = 1; //保存铃声的Uri的字符串形式 private String mRingtoneUri = null;

[java] view plain copy print ?
  1. private void doPickRingtone() {
  2. Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
  3. // Allow user to pick 'Default'
  4. intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
  5. // Show only ringtones
  6. intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
  7. RingtoneManager.TYPE_RINGTONE);
  8. // Don't show 'Silent'
  9. intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
  10. Uri ringtoneUri;
  11. if (mRingtoneUri != null) {
  12. ringtoneUri = Uri.parse(mRingtoneUri);
  13. } else {
  14. // Otherwise pick default ringtone Uri so that something is
  15. // selected.
  16. ringtoneUri = RingtoneManager
  17. .getDefaultUri(RingtoneManager.TYPE_RINGTONE);
  18. }
  19. // Put checkmark next to the current ringtone for this contact
  20. intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
  21. ringtoneUri);
  22. // Launch!
  23. // startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE);
  24. startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE);
  25. }
private void doPickRingtone() { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); // Allow user to pick 'Default' intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); // 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 = 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.选择铃声之后作相应的处理,可以存储到数据库。

[java] view plain copy print ?
  1. @Override
  2. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  3. if (resultCode != Activity.RESULT_OK) {
  4. return;
  5. }
  6. switch (requestCode) {
  7. case REQUEST_CODE_PICK_RINGTONE: {
  8. Uri pickedUri = data
  9. .getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
  10. handleRingtonePicked(pickedUri);
  11. break;
  12. }
  13. }
  14. }
  15. private void handleRingtonePicked(Uri pickedUri) {
  16. if (pickedUri == null || RingtoneManager.isDefault(pickedUri)) {
  17. mRingtoneUri = null;
  18. } else {
  19. mRingtoneUri = pickedUri.toString();
  20. }
  21. // get ringtone name and you can save mRingtoneUri for database.
  22. if (mRingtoneUri != null) {
  23. rintoneNameView.setText(RingtoneManager
  24. .getRingtone(this, pickedUri).getTitle(this));
  25. } else {
  26. rintoneNameView.setText(getString(R.string.default_ringtone));
  27. }
  28. // ContentValues values = new ContentValues();
  29. // values.put(Contacts.CUSTOM_RINGTONE, mRingtoneUri);
  30. // //mContactId mean contacts id
  31. // getContentResolver().update(Contacts.CONTENT_URI, values,
  32. // Contacts._ID + " = " + mContactId, null);
  33. }  

你可能感兴趣的:(java,数据库,String,user,null,存储)