Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Unable to Open the Front Camera - Xamarin Android #941

Open
Auto72 opened this issue Feb 23, 2022 · 3 comments
Open

Unable to Open the Front Camera - Xamarin Android #941

Auto72 opened this issue Feb 23, 2022 · 3 comments

Comments

@Auto72
Copy link

Auto72 commented Feb 23, 2022

It seems there is no way to open the front camera and take a picture using the media plugin.
I tried:

var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions{ DefaultCamera = CameraDevice.Front });

But it opens the Rear Camera always on my Samsung SM-T545 (Android 11) device.
The Camera2Basic xamarin android sample it is able to open the front camera.
I updated and attached that project. Can you have a look, in order to understand how to select the front camera ?

Bug Information

Version Number of Plugin: 5.0.1
Device Tested On: Samsung SM-T545
Simulator Tested On:
Version of VS: 2022
Version of Xamarin: Xamarin.AndroidX.AppCompat 1.3.1.5
Versions of other things you are using:

Steps to reproduce the Behavior

var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions{ DefaultCamera = CameraDevice.Front });

Expected Behavior

Front Camera opens

Actual Behavior

Rear Camera opens

Code snippet

var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions{ DefaultCamera = CameraDevice.Front });

Screenshots

none

@Auto72
Copy link
Author

Auto72 commented Feb 23, 2022

I can't attach the zip file I prepared, it says "is not included in the list" :-( when I select or drag and drop the file.

@Auto72
Copy link
Author

Auto72 commented Feb 23, 2022

The following works for Samsung:

        var cacheName = System.IO.Path.Combine(CacheDir.AbsolutePath, System.IO.Path.GetTempFileName());
        using var cacheFile = new Java.IO.File(cacheName);
        using var photoURI = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", cacheFile);
        using var cameraIntent = new Intent(MediaStore.ActionImageCapture);
        cameraIntent.PutExtra(MediaStore.ExtraOutput, photoURI);

        cameraIntent.PutExtra("com.google.assistant.extra.USE_FRONT_CAMERA", true);
        cameraIntent.PutExtra("android.intent.extra.USE_FRONT_CAMERA", true);
        cameraIntent.PutExtra("android.intent.extras.LENS_FACING_FRONT", 1);
        cameraIntent.PutExtra("android.intent.extras.CAMERA_FACING", 1);

        // Samsung
        cameraIntent.PutExtra("camerafacing", "front");
        cameraIntent.PutExtra("previous_mode", "front");

        StartActivityForResult(cameraIntent, _CAMERA_PHOTO_REQUEST_CODE); 

Here you can find also for Huawei:
https://stackoverflow.com/questions/9686203/how-to-launch-front-camera-with-intent

// Huawei
putExtra("default_camera", "1")
putExtra("default_mode", "com.huawei.camera2.mode.photo.PhotoMode")

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant