我想要一个自定义铃声。我能够检查铃声,但无法将其设置为铃声。我在找到该铃声的URI方面遇到了问题。
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select
ringtone:");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT,
true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_ALL);
startActivityForResult(intent, 1);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case 1:
/*Toast.makeText(getBaseContext(),
RingtoneManager.ID_COLUMN_INDEX, Toast.LENGTH_SHORT).show();
Uri targetUri = data.getData();*/
Uri uri = data.getData();
String[] ringTonePath = new String[0];
ringTonePath[0] = uri.getPath();
Cursor c = getContentResolver().query(uri, ringTonePath, null, null, null);
int columnIndex = c.getColumnIndex(ringTonePath[0]);
String tonepath = c.getString(columnIndex);
toneurl.setText(tonepath);
Log.w("Path of tone from
home......******************.........", tonepath + "");
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
RingtoneManager.TYPE_NOTIFICATION, uri);
break;
default:
break;
}
答案 0 :(得分:1)
在OnActivityResult内部,使用
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);