Pregunta

Quiero bloquear mi vista de cámara para "Paisaje"modo.Cuando hago clic en el botón simple en mi aplicación, se abrirá la cámara de ese dispositivo de tiempo y eso la cámara debe estar bloqueada para "Modo horizontal".¿Alguien puede saber la solución de este problema?

Estoy usando este código dentro de " CaptureImageActivity.actividad" java".Entonces, después de la ejecución de esta actividad, se abrirá la cámara de mi sistema.

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);

        }
    });

Y quiero bloquear la vista de la cámara en "Modo Horizontal".Y según la solución

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

Solo la actividad "CaptureImageActivity" está bloqueada en "Modo Horizontal".

¿Fue útil?

Solución

Agregue esto a su actividad dentro del archivo de manifiesto

android:screenOrientation="portrait"

Otros consejos

consulte este enlace para bloquear la orientación de la cámara, use setDisplayOrientation (int degrees)

la documentación se puede encontrar en el siguiente enlace :http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29

para más detalles, consulte esta respuesta :

¿Cómo configurar correctamente la orientación de la cámara de Android?

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);
 }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top