如何从相应的 Ringtonemanager 获取铃声 URI [重复]
Posted
技术标签:
【中文标题】如何从相应的 Ringtonemanager 获取铃声 URI [重复]【英文标题】:How to get the ringtone URI from the respective Ringtonemanager [duplicate] 【发布时间】:2015-04-23 09:05:10 【问题描述】:我想要一个自定义铃声。我可以检查铃声,但无法将其设置为铃声。我在查找该铃声的 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;
【问题讨论】:
java.lang.RuntimeException: 传递结果失败 ResultInfowho=null, request=1, result=-1, data=Intent dat=content://media/external/audio/media/ 15(有附加功能) 到活动 com.example.rknikhil.myapplication/com.example.rknikhil.myapplication.MainActivity:java.lang.ArrayIndexOutOfBoundsException:length=0;索引=0 我收到上述错误 【参考方案1】:在 OnActivityResult 中,使用
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
【讨论】:
以上是关于如何从相应的 Ringtonemanager 获取铃声 URI [重复]的主要内容,如果未能解决你的问题,请参考以下文章