简体   繁体   English

从 SQLITE Android 获取图像 Uri

[英]Get Image Uri from from SQLITE Android

I have a problem with displaying the photo by getting the URI from SQLite.我在通过从 SQLite 获取 URI 来显示照片时遇到问题。 I picked up an image from gallery using these lines:我使用这些行从画廊中挑选了一张图片:

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

then I received the intent like this in onActivityResult :然后我在onActivityResult收到了这样的意图:

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

The image is displayed well in ImageView and there is no problem.图像在 ImageView 中显示良好,没有问题。 But when I stored it in SQLite as String using toString method like this: imageUri.toString() .但是当我使用这样的 toString 方法将它作为字符串存储在 SQLite 中时: imageUri.toString() I got this string from SQLite then parsed it to URI again and tried to display it with imageView put this problem appeared:我从 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

what is the problem here, and why I could display the image before storing it and could not display it again after getting it from SQLite!这里有什么问题,为什么我可以在存储之前显示图像并且在从 SQLite 获取图像后无法再次显示它!

store image URI in sqlite is very bad idea.在 sqlite 中存储图像 URI 是非常糟糕的主意。 if the path is delete then your app does not retrieve the image.如果路径被删除,那么您的应用程序不会检索图像。 So if you want to store image in sqlite then convert your image in byte[] and store this byte[] in sqlite in a BLOB column.因此,如果您想将图像存储在 sqlite 中,然后将图像转换为 byte[] 并将此 byte[] 存储在 sqlite 中的 BLOB 列中。 when you retrieve BOLB then convert byte[] to image and show into image view.当您检索 BOLB 时,然后将 byte[] 转换为图像并显示为图像视图。

if you don't understand how to store then see this link:如果您不了解如何存储,请查看此链接:

https://abhiandroid.com/database/add-retrieve-image-sqlite-database-example-android-studio.html 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