3

I have an app that requires multiple permissions to be checked and requested if not there. So when the app runs the first time, it skips all the function calls that are after it, even after clicking on allow access

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
        != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    // Check Permissions Now
    ActivityCompat.requestPermissions(
            this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            REQUEST_CODE_LOCATION);
}
// Will not be called the first time
functionCall()

Is there any way to not call the function until the user hits allow access

kris larson
  • 30,387
  • 5
  • 62
  • 74
Mohamad Zein
  • 777
  • 1
  • 8
  • 33
  • I think you should refer to this. http://stackoverflow.com/questions/30719047/android-m-check-runtime-permission-how-to-determine-if-the-user-checked-nev – niravmodi Jul 22 '16 at 21:15

1 Answers1

3

You have to think of requestPermissions like startActivityForResult. It just starts the UI for the user to grant/deny permissions.

Like onActivityResult, you have to override onRequestPermissionsResult to know when the permissions process is complete. You can check if the permissions were granted or denied, and execute your logic from there.

kris larson
  • 30,387
  • 5
  • 62
  • 74