简体   繁体   English

当相机应用程序打开以在android studio中获取图像时,您可以打开图库吗?

[英]Can you open gallery when camera app is open to get images in android studio?

I'm working on an native android application in Java.我正在使用 Java 开发本机 android 应用程序。 I have already implemented camera functionalities that upload images to firebase storage when captured, but I expected that you could also open your gallery from the camera and upload those images like facebook messenger.我已经实现了相机功能,可以在捕获时将图像上传到 firebase 存储,但我希望您也可以从相机打开您的图库并上传这些图像,例如 facebook messenger。 Until now I have only found tutorials that separate camera and gallery with a menu that appears by clicking an add button .到目前为止,我只找到了通过单击添加按钮出现的菜单将相机和图库分开的教程。

Where gallery should normally be located in the camera application图库通常应位于相机应用程序中的位置

Facebook messenger is implementing their own gallery, reading files probably from MediaStore. Facebook messenger 正在实施他们自己的画廊,可能从 MediaStore 读取文件。

If you want to open the gallery from your app and pick a picture you should launch an intent:如果您想从您的应用程序打开图库并选择一张图片,您应该启动一个意图:

private val pickImageFromGallery = registerForActivityResult(ActivityResultContracts.GetContent()) { 
  uri: Uri? ->
    uri?.let { 
      // handle the data here
    }
}

Then launch the intent from a button click or something else:然后通过单击按钮或其他方式启动意图:

pickImageFromGallery.launch("image/*")

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

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