【发布时间】:2012-07-09 14:08:40
【问题描述】:
在我的代码中,我将声音文件设置为铃声。它大多工作正常。
这个问题是它没有使用 ContentValue 的 TITLE 条目作为铃声列表中的铃声名称。在下面的代码中,我将 TITLE 键设置为“自定义名称”。但在铃声选择列表中却坚持显示为“testTone”(文件名为“testTone.mp3”)。
// Take the given file and add it to the ringtone list
private Uri makeRingtone(File soundFile) {
String path = soundFile.getAbsolutePath();
// Make sure the system knows about it
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.parse("file://"+path)));
// Plug in same important values
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, path);
values.put(MediaStore.MediaColumns.TITLE, "Custom Name");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
// The ol' delete then insert trick:
Uri uri = MediaStore.Audio.Media.getContentUriForPath(path);
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + path + "\"", null);
Uri newUri = getContentResolver().insert(uri, values);
Log.d(TAG, "New Uri: " + newUri);
return newUri;
}
这与问题类似:Saving sounds as ringtones using the title of the sound instead of number location
【问题讨论】:
标签: java android audio notifications ringtone