Android Save Sound as Ringtone - 标题未在铃声列表中使用

时间:2012-07-09 14:08:40

标签: java android audio notifications ringtone

在我的代码中,我将声音文件设置为铃声。它大部分工作正常。

此问题是它不会在铃声列表中使用ContentValue的TITLE条目作为铃声名称。在以下代码中,我将TITLE键设置为“Custom Name”。但在铃声选择列表中,它坚持显示为“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

1 个答案:

答案 0 :(得分:0)

删除此行,铃声将显示正确的标题:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
      Uri.parse("file://"+path)));