【问题标题】:Android Saving Sound as Ringtone - Title not being used in Ringtone ListAndroid 将声音保存为铃声 - 铃声列表中未使用标题
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多