Android: set the ringtone for an existing recording in Mediastore.Audio.Media

I can set the ringtone perfectly when I insert a line in Mediastore.Audio.Media

 newUri = this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values); 

But for an existing record, when I try to insert a row again, logcat shows me database restriction error 19. So, how do I get around this? Basically I need to install the .ogg file from my soundcard application as a ringtone that already exists in the reseller database ... Any help is appreciated.

+3
source share
1 answer

I get it. Before inserting, delete the existing entry in the database.

Uri uri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + file.getAbsolutePath() + "\"", null);

Hope this helps too.

+3
source

Source: https://habr.com/ru/post/1777988/


All Articles