简体   繁体   English

Android Surfaceview相机

[英]Android surfaceview camera

I have loaded camera in surfaceview. 我已经在Surfaceview中加载了相机。 But during first time APK installation, after asking the runtime permissions the app shows black screen instead of camera preview. 但是在首次安装APK时,在询问运行时权限后,该应用会显示黑屏而不是摄像头预览。 But in the second usage of app, the camera preview works perfectly. 但是,在第二次使用该应用程序时,相机预览效果很好。

You need to setup your camera after the permission has been granted, or if the permission is granted. 您需要在授予权限后或授予权限后设置摄像机。

// Activity

    // pseudocode
    void onCreate {
        if (permissionGranted) {
            // setup camera
        } else {
            // ask permission and do setup camera at onRequestPermissionsResult
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        // do your camera setup here
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM