MediaStore.Media.Images Android/ Kotlin:如何对用户隐藏图库中保存的照片?

MediaStore.Media.Images Android/ Kotlin: How to hide photos saved in gallery from user?

我正在使用以下程序使用 MediaStore.ACTION_IMAGE_CAPTURE cameraIntent.

捕获图像

代码:

val values = ContentValues()
values.put(MediaStore.Images.Media.TITLE, "New Picture")
values.put(MediaStore.Images.Media.DESCRIPTION, "From the Camera")
imageUri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
//camera intent
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
startActivityForResult(cameraIntent, IMAGE_CAPTURE_CODE)

我有以下问题:

我尝试将 EXTERNAL_CONTENT_URI 更改为 INTERNAL_CONTENT_URI,但这给了我以下警告:Writing to internal storage is not supported android

一旦您使用媒体商店,它们就在 'the gallery'。

所以你必须使用 getFilesDir() 和经典的文件方法来保存它们只供你查看。

The image that has been captured is being shown in the gallery. How do I hide that from the user?

作为 blackapps have said, and in accordance to this documentation, which states that MediaStore API uses shared storage, you can't use MediaStore API to store in app-specific storage(不是图库)。

这个documentation provides an example of storing photos to app specific storage using getExternalFileDir().

After taking the image, I am setting the photo in a ImageView that is lagging the activity. How can I compress the image when I am setting it to the ImageView?

试试 Glide, a fast and efficient image loading library for Android. In addition, as I'm typing this, CommonsWare 也推荐了Picasso、Coil等其他图片加载库

Is there a way to click photos only in portrait mode?

也许 ImageView 的这个 might help. You can set theclickable 属性以编程方式或声明方式。