How to ask runtime permissions for Camera in Android , Runtime storage permissions

后端 未结 6 1026
迷失自我
迷失自我 2020-12-01 16:47

I am doing an application to scan barcodes on a button click and it was working fine up to Lollipop versions. When I came to Marshmallow it stopped working. This is the erro

6条回答
  •  不知归路
    2020-12-01 17:16

        if (ContextCompat.checkSelfPermission(getContext(),
                Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
    
            if (ActivityCompat.shouldShowRequestPermissionRationale((Activity)
                    getContext(), Manifest.permission.CAMERA)) {
    
    
            } else {
                ActivityCompat.requestPermissions((Activity) getContext(), 
                        new String[]{Manifest.permission.CAMERA},
                        MY_PERMISSIONS_REQUEST_CAMERA);
            }
    
        }
    

提交回复
热议问题