1. 程式人生 > >解決android6.0開啟攝像頭許可權"Failed to connect to camera service"的問題 ,動態獲取許可權

解決android6.0開啟攝像頭許可權"Failed to connect to camera service"的問題 ,動態獲取許可權

android6.0使用camera.open()時需要在onCreate()裡面新增如下程式碼,否則會報錯"Failed to connect to camera service":

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {             if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {                 requestPermissions(new String[] {Manifest.permission.CAMERA}, 1);             }         }

幾行程式碼輕鬆搞定