繁体   English   中英

从 SQLITE Android 获取图像 Uri

[英]Get Image Uri from from SQLITE Android

我在通过从 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[] 存储在 sqlite 中的 BLOB 列中。 当您检索 BOLB 时,然后将 byte[] 转换为图像并显示为图像视图。

如果您不了解如何存储,请查看此链接:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM