question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure to use only front camera

See original GitHub issue

Is your feature request related to a problem? Please describe. When starting with cameraOnly() I would like to be able to set ImagePicker to either A) only allow the front camera or B) start with the front camera and allow the user to switch to the rear camera.

Describe the solution you’d like For either of the cases above, a config option similar to cameraOnly like frontCameraOnly or startFrontCamera that either restricts user to front camera, or starts them off with it.

Describe alternatives you’ve considered I tried overriding the provider methods in library, but haven’t had much luck with it.

Additional context Basically I’m using this library to capture or pick profile photos. Those are typically taken as selfies and not from the rear camera.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ArisChoicecommented, Nov 8, 2021

@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
    }
1reaction
shobhikcommented, Nov 21, 2021

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I switch to the front-facing camera on a Microsoft ...
Open Windows Device Manager (Right click on the Windows menu, select Device Manager) · Scroll down to System Devices; click to expand the...
Read more >
Use Camera Switches - Android Accessibility Help
Set up Camera Switches & assign facial gestures to action · Choose your gesture size · Choose your gesture duration · Use gestures...
Read more >
Change advanced camera settings on iPhone - Apple Support
Lens Correction is on by default. To turn off Lens Correction, go to Settings > Camera, then turn off Lens Correction.
Read more >
Media & Sound Camera settings menu (front and rear camera)
1. Capture your special moments the way you want with your Samsung Galaxy S10. You can take photos and record videos on your...
Read more >
Android configuration for camera "front" vs 'rear" - Stack Overflow
I am using it for testing some cameras that attach via the micro USB port. When testing applications they seem to have a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found