从SQLITE Android获取图像Uri



通过从SQLite获取URI来显示照片时遇到问题。我用以下几行从图库中提取了一张图片:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
someActivityResultLauncher.launch(intent);

然后我在onActivityResult:中收到了这样的意图

Intent data = result.getData();
imageUri = data.getData();
circleImageView.setImageURI(imageUri);

图像在ImageView中显示良好,没有问题。但是当我使用toString方法将它作为字符串存储在SQLite中时,如下所示:imageUri.toString()。我从SQLite得到了这个字符串,然后再次将其解析为URI,并试图用imageView显示它。出现了这个问题:

Permission Denial: opening provider com.miui.gallery.provider.GalleryOpenProvider from ProcessRecord{35f7837 4773:com.example.booklibrary/u0a538} (pid=4773, uid=10538) that is not exported from UID 10096

这里的问题是什么,以及为什么我可以在存储图像之前显示它,而在从SQLite获得图像之后却不能再次显示它!

在sqlite中存储映像URI是个非常糟糕的主意。如果路径被删除,那么你的应用程序不会检索到图像。因此,如果您想将图像存储在sqlite中,请将图像转换为byte[],并将此byte[]存储在sqlte中的BLOB列中。检索BOLB时,将byte[]转换为图像并显示在图像视图中。

如果你不知道如何存储,请查看此链接:

https://abhiandroid.com/database/add-retrieve-image-sqlite-database-example-android-studio.html

最新更新