Я хочу осуществить набор мелодии для моего приложения, после записи voice.Ringtone будет установлена правильно только один раз, когда он будет установлен в качестве мелодии звонка, а снова установить ее не работает должным образом здесь я добавил мой код:Android рингтон установлен программно?
String filepath ="/sdcard/sample/"+currentName+"";
System.out.println("/sdcard/sample/"+currentName+"");
File ringtoneFile = new File(filepath);
ContentValues content = new ContentValues();
content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath());
content.put(MediaStore.MediaColumns.TITLE, currentName);
content.put(MediaStore.MediaColumns.SIZE, 215454);
content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
// content.put(MediaStore.Audio.Media.ARTIST, "Madonna");
content.put(MediaStore.Audio.Media.DURATION, 230);
content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
content.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
content.put(MediaStore.Audio.Media.IS_ALARM, true);
content.put(MediaStore.Audio.Media.IS_MUSIC, true);
String Ringtonepath= "content://media/internal/audio/media/297";
Uri Ringtone1 = Uri.parse(Ringtonepath);
//Insert it into the database
Log.i("TAG", "the absolute path of the file is :"+
ringtoneFile.getAbsolutePath());
Uri uri = MediaStore.Audio.Media.getContentUriForPath(
ringtoneFile.getAbsolutePath());
Uri newUri = getContentResolver().insert(uri, content);
System.out.println("uri=="+uri);
Log.i("TAG","the ringtone uri is :"+newUri);
// getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile.getAbsolutePath() + "\"",
// null);
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(), RingtoneManager.TYPE_RINGTONE,
newUri);
Моей Ошибка ::
Новая мелодия:
TAG the ringtone uri is :content://media/internal/audio/media/297
Существующие рингтон:
TAG the ringtone uri is :null
** Лучшая врезка для установки мелодии здесь ** [Set Ringtone Programatically] (https://stackoverflow.com/questions/40420969/set-a-sound-file-as-ringtone-and-notification-programmatically-in-android/45836076#45836076) –