Android: Set Ringtone for existing record in Mediastore.Audio.Media
I am able to set the ringtone perfectly, when I insert the row in Mediastore.Audio.Media
newUri = this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);
But for an existing record i.e when am trying to insert the row again, logcat shows me database constraint error 19. So how do I work around this?开发者_如何学JAVA Basically I need to set a .ogg file from my sound board app as a ringtone, which is already existing in the mediastore database... Any help is appreciated..
I figured it out. Delete the existing record in the database before inserting.
Uri uri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + file.getAbsolutePath() + "\"", null);
Hope this helps you too.
精彩评论