When to request permission at runtime for Android Marshmallow 6.0?

后端 未结 11 997
故里飘歌
故里飘歌 2020-12-06 05:54

I am testing my app on Marshmallow 6.0 and it\'s getting force closed for the android.permission.READ_EXTERNAL_STORAGE, even if it is defined in th

11条回答
  •  借酒劲吻你
    2020-12-06 06:12

    if ( ActivityCompat.shouldShowRequestPermissionRationale (this, Manifest.permission.CAMERA) ||
                    ActivityCompat.shouldShowRequestPermissionRationale (this,
                            Manifest.permission.RECORD_AUDIO) ) {
                Toast.makeText (this,
                        R.string.permissions_needed,
                        Toast.LENGTH_LONG).show ();
            } else {
                ActivityCompat.requestPermissions (
                        this,
                        new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO},
                        CAMERA_MIC_PERMISSION_REQUEST_CODE);
            }
    

提交回复
热议问题