2012-07-09 158 views
1

在我的代码中,我将声音文件设置为铃声。它大多工作正常。Android将铃声保存为铃声 - 标题未在铃声列表中使用

此问题在于,它没有在铃声列表中使用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

回答

0

删除此行和铃声会显示与适当的标题:

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