在dailog的许可下允许调用后不能调用方法

时间:2019-12-24 18:57:47

标签: android android-permissions android-studio-3.0

Android Studio 3.6

在我的活动中:

     private val REQUEST_CODE_CAMERA = 1;

override fun onResume() {
    super.onResume()
    val cameraPermission = Manifest.permission.CAMERA
    val permissionCheck = ContextCompat.checkSelfPermission(this, cameraPermission)
    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        dataBinding.cameraKitView.onResume()
    } else {
        requestPermissions(arrayOf(cameraPermission), REQUEST_CODE_CAMERA)
    }
}

override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String>,
    grantResults: IntArray
) {
    Debug.d(TAG, "onRequestPermissionsResult: requestCode = $requestCode")
    if (requestCode == REQUEST_CODE_CAMERA) {
        Debug.d(
            TAG,
            "onRequestPermissionsResult: REQUEST_CODE_CAMERA, permissions_size = " + permissions.size
        )
        for (i in permissions.indices) {
            if (permissions[i] == Manifest.permission.CAMERA && grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                Debug.d(TAG, "onRequestPermissionsResult: call_cameraKitView_onResume()")
                dataBinding.cameraKitView.onResume()
            }
        }
    }
}

首次运行应用程序时,显示权限对话框。但是当我单击“允许”然后调用方法:

onRequestPermissionsResult

但是

onRequestPermissionsResult: requestCode = 99107

因此没有呼叫dataBinding.cameraKitView.onResume()

为什么 onRequestPermissionsResult:requestCode 不等于= 1?

0 个答案:

没有答案