Giter Club home page Giter Club logo

Comments (8)

ArisChoice avatar ArisChoice commented on May 24, 2024 2

@Drjacky Update below function in IntentUtils this class:-
https://github.com/Drjacky/ImagePicker/blob/master/imagepicker/src/main/kotlin/com/github/drjacky/imagepicker/util/IntentUtils.kt

This is working for me

/**
     * @return Intent Camera Intent
     */
    @JvmStatic
    fun getCameraIntent(uri: Uri, tryFrontCamera: Boolean): Intent {
        val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)

        if (tryFrontCamera) when {
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {

                intent.putExtra(CAMERA_FACING_EXTRA, CameraCharacteristics.LENS_FACING_FRONT) // Tested on API 27 Android version 8.0(Nexus 6P)
                intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true)// tested on android 11
                intent.putExtra("android.intent.extras.CAMERA_FACING", CameraCharacteristics.LENS_FACING_FRONT)// tested on android 11
                intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);// tested on android 11
            }
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.O -> {
                intent.putExtra(
                    CAMERA_FACING_EXTRA,
                    CameraCharacteristics.LENS_FACING_FRONT
                ) // Tested on API 24 Android version 7.0(Samsung S6)
            }
            Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 -> intent.putExtra(
                CAMERA_FACING_EXTRA,
                1
            ) // Tested API 21 Android version 5.0.1(Samsung S4)
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri)
        } else {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri)
        }

        return intent
    }

from imagepicker.

Drjacky avatar Drjacky commented on May 24, 2024 1

Thanks to @ArisChoice, https://github.com/Drjacky/ImagePicker/releases/tag/2.1.15

P.S Some devices still don't support defining front camera as default - Like OnePlus

from imagepicker.

shobhik avatar shobhik commented on May 24, 2024 1

@Drjacky would you recommend I copy those Intent extras to use this, or somehow try to set tryFrontCamera by intercepting the provider? Not sure what the ideal usage would be. Also thanks @ArisChoice for the update!

from imagepicker.

ArisChoice avatar ArisChoice commented on May 24, 2024

I am Looking for same feature.

from imagepicker.

Drjacky avatar Drjacky commented on May 24, 2024

@ArisChoice Could you please create a pull request and I'll check and if it works, I'll merge it to the codebase. Thanks!

from imagepicker.

Drjacky avatar Drjacky commented on May 24, 2024

@shobhik Pass true to tryFrontCamera parameter in getCameraIntent

from imagepicker.

Ahsan2408 avatar Ahsan2408 commented on May 24, 2024

where do I call this function please give me an example. I am trying to open the front camera at first.

from imagepicker.

Drjacky avatar Drjacky commented on May 24, 2024

@Ahsan2408
https://github.com/Drjacky/ImagePicker/blob/54e52258fed1d3f7765a8382b4415c0e1912c79d/imagepicker/src/main/kotlin/com/github/drjacky/imagepicker/constant/ImageProvider.kt

ImagePicker.with(this)
    //...
    .provider(ImageProvider.BOTH) //Or bothCameraGallery()
    .createIntentFromDialog { launcher.launch(it) }

from imagepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.