简体   繁体   中英

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. 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. 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.

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/*")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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