Java android camera2模拟器摄像头方向错误

Java android camera2模拟器摄像头方向错误,java,android,android-camera2,Java,Android,Android Camera2,我目前正在学习一个教程,并尝试设置android camera 2。这是它的代码 主要活动: import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.graphics.Camera; import android.graphics.ImageFormat; import android.graphics.SurfaceText

我目前正在学习一个教程,并尝试设置android camera 2。这是它的代码

主要活动:

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Camera;
import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.Image;
import android.media.ImageReader;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Size;
import android.util.SparseIntArray;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;

public class MainActivity extends AppCompatActivity {


private static final int REQUEST_CAMERA_PERMISSION_RESULT = 0;
private Button btnCapture;
private TextureView mTextureView;
private TextureView.SurfaceTextureListener mSurfaceTextListener = new TextureView.SurfaceTextureListener() {
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
        setUpCamera(i,i1);
        connectCamera();
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {

    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {

    }
};
private CameraDevice mCameraDevice;
private  HandlerThread mBackgroundHandlerThread;
private Handler mBackgroundHandler;
private static SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
    ORIENTATIONS.append(Surface.ROTATION_0,0);
    ORIENTATIONS.append(Surface.ROTATION_90,90);
    ORIENTATIONS.append(Surface.ROTATION_180,180);
    ORIENTATIONS.append(Surface.ROTATION_270,270);
}
private Size mPreviewSize;
private CaptureRequest.Builder mCaptureRequestBuilder;

private CameraDevice.StateCallback mCameraDeviceStateCallBack = new CameraDevice.StateCallback() {
    @Override
    public void onOpened(@NonNull CameraDevice cameraDevice) {
        mCameraDevice = cameraDevice;
        startPreview();
    }

    @Override
    public void onDisconnected(@NonNull CameraDevice cameraDevice) {
        cameraDevice.close();
        mCameraDevice = null;
    }

    @Override
    public void onError(@NonNull CameraDevice cameraDevice, int i) {
        cameraDevice.close();
        mCameraDevice = null;
    }
};
private String mCameraId;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTextureView = findViewById(R.id.textureView);
}




@Override
protected void onResume() {
    super.onResume();

    startBackgroundThread();

    if (mTextureView.isAvailable()) {
        setUpCamera(mTextureView.getWidth(),mTextureView.getHeight());
        connectCamera();
    } else {
        mTextureView.setSurfaceTextureListener(mSurfaceTextListener);
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_CAMERA_PERMISSION_RESULT) {
        if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getApplicationContext(),
                    "Application will not run without camera services ",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

private void closeCamera() {
    if (mCameraDevice != null) {
        mCameraDevice.close();
        mCameraDevice = null;
    }
}


private void startBackgroundThread() {
    mBackgroundHandlerThread = new HandlerThread("camera2VideoImage");
    mBackgroundHandlerThread.start();

    mBackgroundHandler = new Handler(mBackgroundHandlerThread.getLooper());
}

private void stopBackgroundThread() {
    mBackgroundHandlerThread.quitSafely();
    try {
        mBackgroundHandlerThread.join();
        mBackgroundHandlerThread = null;
        mBackgroundHandler = null;
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

private static int sensorToDeviceRotation(CameraCharacteristics cameraCharacteristics, int deviceOrientation) {
    int sensorOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    deviceOrientation = ORIENTATIONS.get(deviceOrientation);
    return ((sensorOrientation + deviceOrientation + 360) % 360);

}


private void setUpCamera(int width, int height) {
    CameraManager cameraManager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : cameraManager.getCameraIdList()) {
            CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
            if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) ==
                    CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }
            StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

            int deviceOrientation = getWindowManager().getDefaultDisplay().getRotation();
            int totalRotation = sensorToDeviceRotation(cameraCharacteristics,deviceOrientation);
            boolean swapRotation = totalRotation == 90 || totalRotation == 270;
            int rotatedWidth = width;
            int rotatedHeight = height;
            if (swapRotation) {
                rotatedWidth = height;
                rotatedHeight = width;
            }
            mPreviewSize = chooseOptimaSize(map.getOutputSizes(SurfaceTexture.class), rotatedWidth ,
                    rotatedHeight);
            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

private void connectCamera() {
    CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) ==
                    PackageManager.PERMISSION_GRANTED) {
                cameraManager.openCamera(mCameraId, mCameraDeviceStateCallBack, mBackgroundHandler);
            } else {
                if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    Toast.makeText(this,
                            "Video app requires access to camera"
                            ,Toast.LENGTH_SHORT).show();
                }
                requestPermissions(new String[] {Manifest.permission.CAMERA},
                        REQUEST_CAMERA_PERMISSION_RESULT);
            }
        } else {
            cameraManager.openCamera(mCameraId, mCameraDeviceStateCallBack, mBackgroundHandler);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

private void startPreview() {
    SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
    surfaceTexture.setDefaultBufferSize(mPreviewSize.getWidth(),mPreviewSize.getHeight());
    Surface previewSurface = new Surface(surfaceTexture);
    try {
        mCaptureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mCaptureRequestBuilder.addTarget(previewSurface);

        mCameraDevice.createCaptureSession(Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback() {
            @Override
            public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                try {
                    cameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(),
                            null, mBackgroundHandler);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
                Toast.makeText(getApplicationContext(),"unable to setup preview",
                        Toast.LENGTH_SHORT).show();
            }
        } , null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}



private static class CompareSizeByArea implements Comparator<Size> {

    @Override
    public int compare(Size lhs, Size rhs) {
        return Long.signum((long)lhs.getWidth() * lhs.getHeight() /
                (long) rhs.getWidth() * rhs.getHeight());
    }
}

private static Size chooseOptimaSize(Size[] choices, int width, int height) {
    List<Size> bigEnough = new ArrayList<Size>();
    for (Size option : choices) {
        if (option.getHeight() == option.getWidth() * height / width &&
                option.getWidth() >= width && option.getHeight() >= height) {
            bigEnough.add(option);
        }
    }
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizeByArea());
    } else {
        return choices[0];
    }

}


@Override
protected void onPause() {
    closeCamera();
    super.onPause();
    stopBackgroundThread();
    }
}
导入android.Manifest;
导入android.content.Context;
导入android.content.pm.PackageManager;
导入android.graphics.Camera;
导入android.graphics.ImageFormat;
导入android.graphics.SurfaceTexture;
导入android.hardware.camera2.CameraAccessException;
导入android.hardware.camera2.CameraCaptureSession;
导入android.hardware.camera2.CameraCharacteristics;
导入android.hardware.camera2.CameraDevice;
导入android.hardware.camera2.CameraManager;
导入android.hardware.camera2.CameraMetadata;
导入android.hardware.camera2.CaptureRequest;
导入android.hardware.camera2.totalcapturesult;
导入android.hardware.camera2.params.StreamConfigurationMap;
导入android.media.Image;
导入android.media.ImageReader;
导入android.os.Build;
导入android.os.Environment;
导入android.os.Handler;
导入android.os.HandlerThread;
导入android.support.annotation.NonNull;
导入android.support.v4.content.ContextCompat;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.util.Size;
导入android.util.SparseIntArray;
导入android.view.Surface;
导入android.view.SurfaceView;
导入android.view.TextureView;
导入android.view.view;
导入android.widget.Button;
导入android.widget.Toast;
导入java.io.File;
导入java.io.FileNotFoundException;
导入java.io.IOException;
导入java.nio.ByteBuffer;
导入java.util.ArrayList;
导入java.util.array;
导入java.util.Collection;
导入java.util.Collections;
导入java.util.Comparator;
导入java.util.List;
导入java.util.UUID;
公共类MainActivity扩展了AppCompatActivity{
私有静态最终int请求\摄像机\权限\结果=0;
私人按钮;
私有纹理视图mTextureView;
私有TextureView.SurfaceTextRelister mSurfaceTextListener=新TextReview.SurfaceTextRelister(){
@凌驾
SurfaceTexture上的公共空心可用(SurfaceTexture SurfaceTexture,int i,int i1){
设置摄像机(i,i1);
连接摄像头();
}
@凌驾
表面结构尺寸更改的公共空隙(表面结构表面结构,int i,int i1){
}
@凌驾
公共布尔onSurfaceTextureDestroyed(SurfaceTexture SurfaceTexture){
返回false;
}
@凌驾
已更新SurfaceTexture上的公共空间(SurfaceTexture SurfaceTexture){
}
};
私人摄像设备;
私有HandlerThread mBackgroundHandlerThread;
私人处理程序mBackgroundHandler;
专用静态SparseIntArray方向=新SparseIntArray();
静止的{
方向。附加(曲面。旋转_0,0);
方向。附加(表面。旋转_90,90);
方向。附加(表面。旋转_180180);
方向。附加(表面。旋转_270270);
}
私人规模的mPreviewSize;
私有CaptureRequest.Builder mCaptureRequestBuilder;
private CameraDevice.StateCallback mCameraDeviceStateCallBack=新建CameraDevice.StateCallback(){
@凌驾
打开的公共无效(@NonNull CameraDevice CameraDevice){
mCameraDevice=cameraDevice;
startPreview();
}
@凌驾
公共无效onDisconnected(@NonNull CameraDevice CameraDevice){
cameraDevice.close();
mCameraDevice=null;
}
@凌驾
公共无效onError(@NonNull CameraDevice CameraDevice,int i){
cameraDevice.close();
mCameraDevice=null;
}
};
私人字符串mCameraId;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextureView=findviewbyd(R.id.textureView);
}
@凌驾
受保护的void onResume(){
super.onResume();
startBackgroundThread();
if(mTextureView.isAvailable()){
setUpCamera(mTextureView.getWidth(),mTextureView.getHeight());
连接摄像头();
}否则{
mTextureView.setSurfaceTextureListener(mSurfaceTextListener);
}
}
@凌驾
public void onRequestPermissionsResult(int-requestCode,@NonNull-String[]permissions,@NonNull-int[]grantResults){
super.onRequestPermissionsResult(请求代码、权限、授权结果);
if(requestCode==请求\摄像机\权限\结果){
如果(grantResults[0]!=PackageManager.PERMISSION\u已授予){
Toast.makeText(getApplicationContext(),
“没有摄像头服务,应用程序将无法运行”,
吐司。长度(短)。show();
}
}
}
私人摄像机(){
if(mCameraDevice!=null){
mCameraDevice.close();
mCameraDevice=null;
}
}
私有void startBackgroundThread(){
mBackgroundHandlerThread=新HandlerThread(“camera2VideoImage”);
mBackgroundHandlerThread.start();
mBackgroundHandler=新处理程序(mBackgroundHandlerThread.getLooper());
}
私有void stopBackgroundThread(){
mBackgroundHandlerThread.quitSafety();
试一试{
mBackgroundHandlerThread.join();
mBackgroundHandlerThread=null;
mBackgroundHandler=null;
}捕捉(中断异常e){
e、 printStackTrace();
}
}
专用静态int传感器至设备旋转(摄像机特性摄像机特性、int设备定向){
int SENSORATION=cameraCharacteristics.get(cameraCharacteristics.SENSOR\u方向);
deviceOrientation=方向。get(deviceOrientation);
返回((传感器方向+设备方向+360)%360);
}
专用照相机(整数宽度、整数高度){
CameraManager CameraManager=(CameraManager)getSystemService(Context.CAMERA_服务);
试一试{
对于(字符串cameraId:cameraManager.getCameraIdList()){
CameraCharacteristics CameraCharacteristics=cameraManager.getCameraCharacteristics(CameraRAID);
if(摄像机特性.获取(摄像机特性.镜头朝向)
private static final int REQUEST_CAMERA_PERMISSION_RESULT = 0;
private Button btnCapture;
private TextureView mTextureView;
private TextureView.SurfaceTextureListener mSurfaceTextListener = new TextureView.SurfaceTextureListener() {
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
        setUpCamera(i,i1);
        connectCamera();
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {

    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {

    }
};
private CameraDevice mCameraDevice;
private  HandlerThread mBackgroundHandlerThread;
private Handler mBackgroundHandler;
private static SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
    ORIENTATIONS.append(Surface.ROTATION_0,0);
    ORIENTATIONS.append(Surface.ROTATION_90,90);
    ORIENTATIONS.append(Surface.ROTATION_180,180);
    ORIENTATIONS.append(Surface.ROTATION_270,270);
}
private Size mPreviewSize;
private CaptureRequest.Builder mCaptureRequestBuilder;

private CameraDevice.StateCallback mCameraDeviceStateCallBack = new CameraDevice.StateCallback() {
    @Override
    public void onOpened(@NonNull CameraDevice cameraDevice) {
        mCameraDevice = cameraDevice;
        startPreview();
    }

    @Override
    public void onDisconnected(@NonNull CameraDevice cameraDevice) {
        cameraDevice.close();
        mCameraDevice = null;
    }

    @Override
    public void onError(@NonNull CameraDevice cameraDevice, int i) {
        cameraDevice.close();
        mCameraDevice = null;
    }
};
private String mCameraId;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTextureView = findViewById(R.id.textureView);
}




@Override
protected void onResume() {
    super.onResume();

    startBackgroundThread();

    if (mTextureView.isAvailable()) {
        setUpCamera(mTextureView.getWidth(),mTextureView.getHeight());
        connectCamera();
    } else {
        mTextureView.setSurfaceTextureListener(mSurfaceTextListener);
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_CAMERA_PERMISSION_RESULT) {
        if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getApplicationContext(),
                    "Application will not run without camera services ",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

private void closeCamera() {
    if (mCameraDevice != null) {
        mCameraDevice.close();
        mCameraDevice = null;
    }
}


private void startBackgroundThread() {
    mBackgroundHandlerThread = new HandlerThread("camera2VideoImage");
    mBackgroundHandlerThread.start();

    mBackgroundHandler = new Handler(mBackgroundHandlerThread.getLooper());
}

private void stopBackgroundThread() {
    mBackgroundHandlerThread.quitSafely();
    try {
        mBackgroundHandlerThread.join();
        mBackgroundHandlerThread = null;
        mBackgroundHandler = null;
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

private static int sensorToDeviceRotation(CameraCharacteristics cameraCharacteristics, int deviceOrientation) {
    int sensorOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    deviceOrientation = ORIENTATIONS.get(deviceOrientation);
    return ((sensorOrientation + deviceOrientation + 360) % 360);

}


private void setUpCamera(int width, int height) {
    CameraManager cameraManager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : cameraManager.getCameraIdList()) {
            CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
            if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) ==
                    CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }
            StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

            int deviceOrientation = getWindowManager().getDefaultDisplay().getRotation();
            int totalRotation = sensorToDeviceRotation(cameraCharacteristics,deviceOrientation);
            boolean swapRotation = totalRotation == 90 || totalRotation == 270;
            int rotatedWidth = width;
            int rotatedHeight = height;
            if (swapRotation) {
                rotatedWidth = height;
                rotatedHeight = width;
            }
            mPreviewSize = chooseOptimaSize(map.getOutputSizes(SurfaceTexture.class), rotatedWidth ,
                    rotatedHeight);
            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

private void connectCamera() {
    CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) ==
                    PackageManager.PERMISSION_GRANTED) {
                cameraManager.openCamera(mCameraId, mCameraDeviceStateCallBack, mBackgroundHandler);
            } else {
                if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    Toast.makeText(this,
                            "Video app requires access to camera"
                            ,Toast.LENGTH_SHORT).show();
                }
                requestPermissions(new String[] {Manifest.permission.CAMERA},
                        REQUEST_CAMERA_PERMISSION_RESULT);
            }
        } else {
            cameraManager.openCamera(mCameraId, mCameraDeviceStateCallBack, mBackgroundHandler);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

private void startPreview() {
    SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
    surfaceTexture.setDefaultBufferSize(mPreviewSize.getWidth(),mPreviewSize.getHeight());
    Surface previewSurface = new Surface(surfaceTexture);
    try {
        mCaptureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mCaptureRequestBuilder.addTarget(previewSurface);

        mCameraDevice.createCaptureSession(Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback() {
            @Override
            public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                try {
                    cameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(),
                            null, mBackgroundHandler);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
                Toast.makeText(getApplicationContext(),"unable to setup preview",
                        Toast.LENGTH_SHORT).show();
            }
        } , null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}



private static class CompareSizeByArea implements Comparator<Size> {

    @Override
    public int compare(Size lhs, Size rhs) {
        return Long.signum((long)lhs.getWidth() * lhs.getHeight() /
                (long) rhs.getWidth() * rhs.getHeight());
    }
}

private static Size chooseOptimaSize(Size[] choices, int width, int height) {
    List<Size> bigEnough = new ArrayList<Size>();
    for (Size option : choices) {
        if (option.getHeight() == option.getWidth() * height / width &&
                option.getWidth() >= width && option.getHeight() >= height) {
            bigEnough.add(option);
        }
    }
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizeByArea());
    } else {
        return choices[0];
    }

}


@Override
protected void onPause() {
    closeCamera();
    super.onPause();
    stopBackgroundThread();
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextureView
   android:id="@+id/textureView"
   android:layout_width="match_parent"
   android:layout_above="@+id/buttonCapture"
   android:layout_height="match_parent" />

<Button
    android:layout_width="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_height="wrap_content"
    android:id="@+id/buttonCapture"
    android:text="CAPTURE"/>


</RelativeLayout>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidcamera2api">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.hardware.camera2.full" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".CameraActivity"></activity>
</application>

</manifest>
<activity android:name=".MainActivity"
          android:screenOrientation="portrait">