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?