yasirkula/UnityNativeCamera

Using front camera as default

sigvevermandere opened this issue · 6 comments

Description of the bug

Using the preferredCamera argument in TakePicture doesn't seem to work. If I set it to PreferredCamera.Front, it still opens the rear camera.

Reproduction steps

Run the following line:
NativeCamera.TakePicture((string imagePath) => { Debug.Log(imagePath); }, -1, true, NativeCamera.PreferredCamera.Front);

This should still open the rear camera.

Platform specs

  • Unity version: 2020.2.0b2.3094
  • Platform: Android
  • Device: OnePlus Nord Android 11
  • How did you download the plugin: Package Manager

I can also reproduce this issue on some devices but unfortunately, this issue can't be resolved. There is no official way to set the camera direction while launching the native camera app on Android. I'm using all known unofficial methods to set the camera direction but looks like it just doesn't work on all native camera apps.

public static void SetDefaultCamera( Intent intent, boolean useRearCamera )
{
if( useRearCamera )
{
intent.putExtra( "android.intent.extras.LENS_FACING_BACK", 1 );
intent.putExtra( "android.intent.extras.CAMERA_FACING", 0 );
intent.putExtra( "android.intent.extra.USE_FRONT_CAMERA", false );
}
else
{
intent.putExtra( "android.intent.extras.LENS_FACING_FRONT", 1 );
intent.putExtra( "android.intent.extras.CAMERA_FACING", 1 );
intent.putExtra( "android.intent.extra.USE_FRONT_CAMERA", true );
}
}

hmm, okay. Thanks for your quick reply!

Are there any updates on this? Even using NativeCamera.PreferredCamera.Rear I get the front camera on a Samsung S22 Ultra

To my knowledge, there are no updates regarding this issue.

Thank you for the quick reply, that's really unfortunate though :(

Do you know if there is any other way to get a decent camera picture (I just need a single picture) from inside unity for an Android device? What I tried so far is:

  1. Using Unity API to access the camera directly. Unfortunately the picture quality taking a snap like this is really bad, there is a lot of motion blur and the color are very bad.
  2. Using Unity AR Foundation. But the app become very heavy and additionally AR Foundation is not supported on all the recent phones as far as I know (at least there is a list of compatible device, so I guess there must be some incompatible ones even among recent devices).

I don't remember seeing free solutions unfortunately. I had seen NatDevice in the past but it's a paid solution.