我附加了一些代码来获取文件管理器中的单个铃声。我必须从文件管理器中的铃声文件夹中获取多个铃声。
public void ringtone(){
Log.i("TEST", "inside the ringtone");
String filepath = Environment.getExternalStorageDirectory().getAbsolutePath();
Log.i("FilePath", filepath);
filepath = filepath + "/ringtone";
final MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(filepath);
final String title = new File(filepath).getName();
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, title);
values.put(MediaStore.MediaColumns.TITLE, "song");
values.put(MediaStore.MediaColumns.SIZE, "450kb");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
//Insert it into the database
Uri uri = MediaStore.Audio.Media.getContentUriForPath(title);
Log.i("uri", "" + uri);
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + title + "\"", null);
Uri newUri = getApplicationContext().getContentResolver().insert(uri, values);
//Log.i("URI",""+newUri);
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE, newUri);
}
}