SurfaceView 预览Camera
实现步骤
1.增加权限
1 | <uses-permission android:name="android.permission.CAMERA"/> |
2.动态申请权限
//检查访问摄像头权限
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 100);
} else {
//拥有权限
initCameraView();
}
3.为SurfaceView的SurfaceHolder增加回调
类中要实现回调 implements SurfaceHolder.Callback
1 | private void initCameraView() { |