Permission Requests causes infinite loop in OnResume

前端 未结 3 1962
春和景丽
春和景丽 2021-01-17 12:21

In API >= 23, we are required to ask users for permission at run-time. But for some reason, the permissions are causing onResume to be called infinitely. What causes this?

3条回答
  •  温柔的废话
    2021-01-17 12:36

    first, your app needs to check whether you have been granted a particular permission before asking runtime permission.

     if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
                android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        } else {
            ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE);
        }
    

提交回复
热议问题