react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Android Permission handle when use choose not ask me again

Open MuhmdRaouf opened this issue 2 years ago • 5 comments

Your Environment

  • Plugin version: 4.7.1

Expected Behavior

return AUTHORIZATION_STATUS_RESTRICTED when user deny with option ask me again on Android

Actual Behavior

after requesting permission multiple times and deny it, it stop showing the permission prompt but the state stays deny instead of blocked/restricted.

Steps to Reproduce

  1. Install the Plugin on fresh RN app
  2. request permission
  3. deny it multiple times.

Context

I was trying to detect if the user insist of keep pressing deny, I need to know when the plugin is not able to request permission again in order to take the user to another screen where it opens the app setting so the user change the permission manually.

MuhmdRaouf avatar Jun 09 '22 02:06 MuhmdRaouf

only out of curiosity - how does react-native-permission handle it ? https://github.com/zoontek/react-native-permissions#android-flow

Also do you check "never ask again", you don't specify

I'm aware of some vendors having vendor-specific issues as well so you might include your execution environment, (phone vendor+module+API level) https://stackoverflow.com/help/how-to-ask / https://stackoverflow.com/help/mcve

mikehardy avatar Jun 09 '22 12:06 mikehardy

@mikehardy interesting thing also, as a workaround I wanted to use combination between the 2 lib. I used react-native-permission to check for permission as they have blocked state but if I request permission using react-native-background-geolocation react-native-permission always return deny and never reach blocked state, but if i request permission using react-native-permission it keep track of state correctly (that's in android only), IOS working perfectly so far.

import BackgroundGeolocation from 'react-native-background-geolocation';
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

  if (IS_IOS) {
     await BackgroundGeolocation.requestPermission();
   } else {
     const activityRecognitionResult = await request(PERMISSIONS.ANDROID.ACTIVITY_RECOGNITION,);
     if (activityRecognitionResult === RESULTS.GRANTED) {
       const accessFineLocationResult = await request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
       if (accessFineLocationResult === RESULTS.GRANTED) {
         await request(PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION);
       }
     }
   }

and that's how I check for permission

import { checkMultiple, PERMISSIONS } from 'react-native-permissions';

const { ACTIVITY_RECOGNITION, ACCESS_BACKGROUND_LOCATION, ACCESS_FINE_LOCATION } = PERMISSIONS.ANDROID;
const results = await checkMultiple([ACTIVITY_RECOGNITION, ACCESS_FINE_LOCATION, ACCESS_BACKGROUND_LOCATION]);

MuhmdRaouf avatar Jun 09 '22 13:06 MuhmdRaouf

it might be that the combination of the two libraries has caused some mal-interaction, and it might be interesting to do a trivial npx react-native init test app just with this library to double-check that, I can't say for sure. I personally have lots of permissions to manage so I use only react-native-permissions for what it's worth.

Also do you check "never ask again", you don't specify

This question is still outstanding / needs response but on re-read it might be ambiguous. What I mean is "as a user when confronted with the permissions prompt from react-native-background-geolocation do you select 'never ask again' in the dialog box" on the permissions prompt

mikehardy avatar Jun 09 '22 14:06 mikehardy

Yes I have choose deny & don't ask me again the problem is react-native-background-geolocation only support AUTHORIZATION_STATUS_ALWAYS and AUTHORIZATION_STATUS_DENIED as you can see from the lib documentation.

  interface ProviderChangeEvent {
    /**
    * `true` When device location-services are enabled.
    */
    enabled: boolean;
    /**
    * Authorization status of location-services.  For iOS, this will tell you if the user has enabled "Always" or "When in Use" authorization.
    *
    * | Name                                    | Platform      |
    * |-----------------------------------------|---------------|
    * | [[AUTHORIZATION_STATUS_NOT_DETERMINED]] | iOS only      |
    * | [[AUTHORIZATION_STATUS_RESTRICTED]]     | iOS only      |
    * | [[AUTHORIZATION_STATUS_DENIED]]         | iOS & Android |
    * | [[AUTHORIZATION_STATUS_ALWAYS]]         | iOS & Android |
    * | [[AUTHORIZATION_STATUS_WHEN_IN_USE]]    | iOS only      |
    *
    * ### ℹ️ Note:
    * - When Android location permission is **granted**, `status` == [[AUTHORIZATION_STATUS_ALWAYS]], otherwise [[AUTHORIZATION_STATUS_DENIED]].
    */
    status: AuthorizationStatus;
    /**
    * `true` if network geolocation provider is available.
    */
    network: boolean;
    /**
    * `true` if GPS geolocation provider is available.
    */
    gps: boolean;
    /**
    * __`[iOS 14+]`__ iOS 14 has introduced a new __`[Precise: On]`__ switch on the location authorization dialog allowing users to disable high-accuracy location.
    *
    * This attribute shows the state of that switch:
    * - Enabled:  [[BackgroundGeolocation.ACCURACY_AUTHORIZATION_FULL]].
    * - Disabled, [[BackgroundGeolocation.ACCURACY_AUTHORIZATION_REDUCED]].
    *
    * ![](https://dl.dropbox.com/s/dj93xpg51vspqk0/ios-14-precise-on.png?dl=1)
    *
    * @example
    *
    * ```javascript
    * BackgroundGeolocation.onProviderChange((event) => {
    *   let authorizationStatus = event.authorizationStatus;
    *   if (authorizationStatus == BackgroundGeolocation.ACCURACY_AUTHORIZATION_REDUCED) {
    *     // Supply "Purpose" key from Info.plist as 1st argument.
    *     BackgroundGeolocaiton.requestTemporaryFullAccuracy("Delivery").then((accuracyAuthorization) => {
    *       console.log("[requestTemporaryFullAccuracy]: ", accuracyAuthorization);
    *     }).catch((error) => {
    *       console.warn("[requestTemporaryFullAccuracy] ERROR:", error);
    *     });
    *   }
    * });
    * ```
    *
    * __See also:__
    * - [[BackgroundGeolocation.requestTemporaryFullAccuracy]]
    * - [What's new in iOS 14 `CoreLocation`](https://levelup.gitconnected.com/whats-new-with-corelocation-in-ios-14-bd28421c95c4)
    *
    */
    accuracyAuthorization: AccuracyAuthorization;
  }

right now I am handling permission using react-native-permissions I just wanted to know if there's a way to handle the permissions and it's state from react-native-background-geolocation only.

MuhmdRaouf avatar Jun 09 '22 15:06 MuhmdRaouf

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar Sep 21 '22 03:09 stale[bot]