I want to implement set ringtone to my application after recording voice.Ringtone will set correctly only one time it will be set as ringtone while set again its not working
Rearrange the code lines .. From my understanding you insert new ringtone before deleting the old one.Just replace the above code with this.
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(filepath);
//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());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile.getAbsolutePath() + "\"",
null);
Uri newUri = getContentResolver().insert(uri, content);
System.out.println("uri=="+uri);
Log.i("TAG","the ringtone uri is :"+newUri);
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(), RingtoneManager.TYPE_RINGTONE,
newUri);