调用系统铃声设置

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

//用于选择铃声后作相应的判断标记
private static final int REQUEST_CODE_PICK_RINGTONE = 1;
//保存铃声的Uri的字符串形式
private String 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);
	// 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.选择铃声之后作相应的处理,可以存储到数据库。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	if (resultCode != Activity.RESULT_OK) {
		return;
	}

	switch (requestCode) {
	case REQUEST_CODE_PICK_RINGTONE: {
		Uri pickedUri = data
				.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
		handleRingtonePicked(pickedUri);
		break;
	}
	}
}

private void handleRingtonePicked(Uri pickedUri) {
	if (pickedUri == null || RingtoneManager.isDefault(pickedUri)) {
		mRingtoneUri = null;
	} else {
		mRingtoneUri = pickedUri.toString();
	}
	// get ringtone name and you can save mRingtoneUri for database.
	if (mRingtoneUri != null) {
		rintoneNameView.setText(RingtoneManager
				.getRingtone(this, pickedUri).getTitle(this));
	} else {
		rintoneNameView.setText(getString(R.string.default_ringtone));
	}
	// ContentValues values = new ContentValues();
	// values.put(Contacts.CUSTOM_RINGTONE, mRingtoneUri);
	// //mContactId mean contacts id
	// getContentResolver().update(Contacts.CONTENT_URI, values,
	// Contacts._ID + " = " + mContactId, null);
}

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