Skip to content

Commit

Permalink
Popup the app settings for android 11+ instead of requesting for loca…
Browse files Browse the repository at this point in the history
…tion permission

This makes it easier to set the permissions instead of having people select
"when in use" first and then have to go to the app settings later to fix it.
This fixes e-mission/e-mission-docs#608
at least for now
  • Loading branch information
shankari committed Jun 5, 2021
1 parent 1ef4c8f commit e24462e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/android/verification/SensorControlForegroundDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ private void checkAndPromptLocationPermissions() {
SensorControlBackgroundChecker.restartFSMIfStartState(cordova.getActivity());
return;
}
// If this is android 11 (API 30), we want to launch the app settings instead of prompting for permission
// because the default permission prompting does not offer "always" as an option
// https://github.com/e-mission/e-mission-docs/issues/608
// we don't really care about which level of permission is missing since the prompt doesn't
// do anything anyway. If either permission is missing, we just open the app settings
// Note also that we should actually check for VERSION_CODES.R
// but since we are not targeting API 30 yet, we can't do that
// so we use Q (29) + 1 instead. I think that is more readable than 30
if ((Build.VERSION.SDK_INT >= (Build.VERSION_CODES.Q + 1)) &&
(!cordova.hasPermission(SensorControlConstants.LOCATION_PERMISSION) ||
!cordova.hasPermission(SensorControlConstants.BACKGROUND_LOC_PERMISSION))) {
Context mAct = cordova.getActivity();
String msgString = " LOC = "+cordova.hasPermission(SensorControlConstants.LOCATION_PERMISSION)+
" BACKGROUND LOC "+ cordova.hasPermission(SensorControlConstants.BACKGROUND_LOC_PERMISSION)+
" Android R+, so opening app settings anyway";
Log.i(cordova.getActivity(), TAG, msgString);
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", mAct.getPackageName(), null));
mAct.startActivity(intent);
return;
}
if(!cordova.hasPermission(SensorControlConstants.LOCATION_PERMISSION) &&
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) &&
!cordova.hasPermission(SensorControlConstants.BACKGROUND_LOC_PERMISSION)) {
Expand Down

0 comments on commit e24462e

Please sign in to comment.