When to request permission at runtime for Android Marshmallow 6.0?

后端 未结 11 968
故里飘歌
故里飘歌 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:32

    calling this function we can allow user to open dialog for asking permission to allow camera and record Audio.

        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);
        }
    

提交回复
热议问题