NullPointerException when trying to check permissions

后端 未结 2 1944
长情又很酷
长情又很酷 2021-01-01 13:43

I\'m trying to check if the user has android.Manifest.permission.ACCESS_FINE_LOCATION enabled. When running the application, I get a NullPointerException error.

pack

2条回答
  •  难免孤独
    2021-01-01 14:18

    if (ActivityCompat.checkSelfPermission(ActivityName.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(ActivityName.this, new String[]{
            android.Manifest.permission.ACCESS_FINE_LOCATION
    }, 10);
    

    }

    Try with your ActivityName.this

提交回复
热议问题