2

When I have not upgraded to 4.4.2,front camera is supported the screen is opened in landscape mode but when I upgrade to latest version the front mode is not supported in camera and it is rotating to portrait mode .

My source code to open camera is below:

private void getPhotoFromCamera() 
    {
        try 
        {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra("android.intent.extras.CAMERA_FACING",1);
             VisitorRegistrationFragment.this.startActivityForResult(intent,FROM_CAMERA);
         } 
         catch (Exception e) 
         {
            e.printStackTrace();
         } 
         catch (OutOfMemoryError e) 
         {
            e.printStackTrace();
         }

    }

Can anyone please help me out on how to open front camera and how to restrict the camera to open only in landscape mode ?

Chris
  • 6,105
  • 6
  • 38
  • 55
moturi manasa
  • 73
  • 1
  • 7

2 Answers2

0

You can try to put the orientation in the intent :

intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

And if you set your activity in the Manifest add :

<activity
    android:name="yourLandscapeActivity"
    android:screenOrientation="landscape"              
</activity>
Brian
  • 303
  • 4
  • 16
-1

Simply define your activity in landscape mode

android:screenOrientation="landscape"

and to open front facing camera use below code

private Camera openFrontFacingCameraGingerbread() {
    int cameraCount = 0;
    Camera cam = null;
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    cameraCount = Camera.getNumberOfCameras();
    for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
        Camera.getCameraInfo(camIdx, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            try {
                cam = Camera.open(camIdx);
            } catch (RuntimeException e) {
                Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
            }
        }
    }

    return cam;
}

refer link How do I open the "front camera" on the Android platform?

Community
  • 1
  • 1
Anjali Tripathi
  • 1,477
  • 9
  • 28