Lock camera view in landscape mode in android

I want to block the camera view . When I click on a simple button in my application, this deviceโ€™s camera will be open and the camera should be locked until โ€œ Landscape mode โ€. Can anyone know a solution to this problem?

I use this code inside the action "CaptureImageActivity.java". Therefore, after performing this action, my system camera will open.

btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i=new Intent(android.provider.MediaStore. ACTION_IMAGE_CAPTURE); i.putExtra(android.provider.MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); startActivityForResult(i,1000); } }); 

And I want to block this view of the camera in the "LandScape Mode". And according to the decision

 <activity android:name=".CaptureImageActivity" android:screenOrientation="landscape" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 

CaptureImageActivity is locked in LandScape mode.

+4
source share
3 answers

Add this to your activity inside the manifest file

 android:screenOrientation="portrait" 
0
source

see this link to block the orientation of your camera, use setDisplayOrientation (int degrees)

The documentation can be found at the following link: http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29

for more details see this answer:

How to adjust the orientation of the Android camera?

+1
source
 By using setCameraDisplayOrientation= public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } 
0
source

Source: https://habr.com/ru/post/1437179/


All Articles