gpt4 book ai didi

android - 从 MediaStore 中删除相册?

转载 作者:行者123 更新时间:2023-11-29 20:29:21 29 4
gpt4 key购买 nike

我想知道如何从 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)

最佳答案

试试这个:

    public void deleteAlbum(Context context, int _id) {
Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
ContentResolver resolver = context.getContentResolver();
resolver.delete(uri, MediaStore.Audio.Albums._ID + " = " + _id, null);
}

关于android - 从 MediaStore 中删除相册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224433/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com