从MediaStore删除相册?

时间:2015-08-26 10:41:23

标签: android mediastore

我试图找出如何从MediaStore中删除相册。

我已成功设置从MediaStore删除单首和多首歌曲,现在想知道如何从中删除相册?

如果有人可以帮助我,那就太好了。

修改

以下是我现在提出的问题,但我遇到了崩溃:

   public static void deleteAlbum(ContentResolver resolver, long id)
{
    Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id);
    resolver.delete(uri, null, null);
}

这是崩溃:

Caused by: java.lang.UnsupportedOperationException: Unknown or unsupported URL: content://media/external/audio/albums/48
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:169)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
        at android.content.ContentProviderProxy.delete(ContentProviderNative.java:519)
        at android.content.ContentResolver.delete(ContentResolver.java:1006)
        at com.test.test.test.test.Helpers.deleteAlbum(Helpers.java:48)
        at com.test.test.test.test.FragmentAlbums$deleteAlbum.doInBackground(FragmentAlbums.java:796)
        at com.test.test.test.test.FragmentAlbums$deleteAlbum.doInBackground(FragmentAlbums.java:775)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)

1 个答案:

答案 0 :(得分:1)

我已经对此进行了进一步的研究并解决了这个问题。以下作品。但是,请确保您实际上也删除了SD卡上的相册。见先前的评论

    public void deleteAlbum(Context context, int _id) {

    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    ContentResolver resolver = context.getContentResolver();
    resolver.delete(uri, MediaStore.Audio.Media.ALBUM_ID + " = " + _id, null);
}