Search code examples
androidkotlinandroid-intentandroid-camera-intent

No gallery button in camera action intent


I am developing a webview app. So far I have managed to directly open the camera when the user taps a file input, using MediaStore.ACTION_IMAGE_CAPTURE.

However, the camera action opens the stock camera app, but does not show the existing image picker in the bottom right. Yet when I open the stock camera app from outside of my app, there is a circle in the bottom right, with an image preview, right next to the shutter button.

How can I get this button to show up in my app as well? Obviously I tried to find it by googling, but I can only find answer on how to show the user a dialog where they can pick a photo from either the camera or gallery. But nothing on how to show the "pick from gallery"-button in the camera action. If anyone can point me to the right direction, that would be very much appreciated :)

This is the full method I'm using:

override fun onShowFileChooser(
    webView: WebView?,
    filePathCallback: ValueCallback<Array<Uri>>?,
    fileChooserParams: WebChromeClient.FileChooserParams?
): Boolean {
    val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)

    // Double check that we don't have any existing callbacks
    [email protected]?.onReceiveValue(null)
    [email protected] = filePathCallback

    if (takePictureIntent.resolveActivity(activity.packageManager) != null) {
        // create file where image should go
        var photoFile: File? = null

        try {
            photoFile = createImageFile()
            takePictureIntent.putExtra("PhotoPath", cameraPhotoPath)
        } catch (exception: IOException) {
            Log.e("imageError", "Unable to create image file", exception)
        }

        if (photoFile != null) {
            cameraPhotoPath = "file:${photoFile.absolutePath}"
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile))
        }
    }

    val contentSelectionIntent = Intent(Intent.ACTION_CHOOSER).apply {
        addCategory(Intent.CATEGORY_OPENABLE)
        this.type = "image/*"
    }

    val chooserIntent = Intent(Intent.ACTION_CHOOSER).apply {
        putExtra(Intent.EXTRA_INTENT, contentSelectionIntent)
        putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(takePictureIntent))
    }

    activity.startActivityForResult(chooserIntent, inputFileRequestCode)

    return true
}

Solution

  • However, the camera action opens the stock camera app, but does not show the existing image picker in the bottom right.

    There are ~26,000 Android device models. These ship with hundreds of different "stock" camera apps. Your ACTION_IMAGE_CAPTURE Intent might start any of those, or any one of hundreds of other camera apps that the user might have installed from the Play Store or elsewhere.

    None have to have an "existing image picker in the bottom right" in any conditions.

    How can I get this button to show up in my app as well?

    You don't.

    Presumably, the developers of that camera app decided not to offer that option for ACTION_IMAGE_CAPTURE. For example, perhaps the way they built that feature would break their ability to property return a result to the startActivityForResult() call used with ACTION_IMAGE_CAPTURE. That is their decision, as it is their camera app.