HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
56 stars 64 forks source link

Android ask for ACCESS_BACKGROUND_LOCATION on API > 30 #164

Closed oudoken closed 11 months ago

oudoken commented 11 months ago

Hello there, How about adding the "ACCESS_BACKGROUND_LOCATION" request permission as a function for android API > 30?

Google Play store it's asking for this in some apps.

I've implemented by adding To "BackgroundGeolocationFacade.java" :

public static final String[] PERMISSIONS_BG = { Manifest.permission.ACCESS_BACKGROUND_LOCATION };

and

` public static void ask_bgl_permission(Context context) {

    PermissionManager permissionManager = PermissionManager.getInstance(context);
    permissionManager.checkPermissions(Arrays.asList(PERMISSIONS_BG), new PermissionManager.PermissionRequestListener() {
        @Override
        public void onPermissionGranted() {

        }

        @Override
        public void onPermissionDenied() {

        }
    });
}`

Added also To "BackgroundGeolocationPlugin.java" :

public static final String ACTION_ASK_BGL_PERMISSION = "ask_bgl_permission";

and

else if (ACTION_ASK_BGL_PERMISSION.equals(action)) { BackgroundGeolocationFacade.ask_bgl_permission(context); return true; }

In this way it's possibile to request this permission at any time and android will show the location permission of the app directly, where You can select "Allow all the time".

This is as said somewhat required by the "Google Play Policy - Declared permissions and in-app disclosures" as in this video: https://www.youtube.com/watch?v=b0I1Xq_iSK4&t=1s

HarelM commented 11 months ago

This requires an extra approval from Google when submitting to the store. I would like to avoid this request for most users. Generally speaking, this permission is not needed in order to run the application when the app is not top most. See the following thread: https://github.com/HaylLtd/cordova-background-geolocation-plugin/issues/19

It's confusing, I know...

oudoken commented 11 months ago

Hi @HarelM, So if understand correctly, You say that i can remove:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

From AndroidManifest.xml and just use the FOREGROUND SERVICE?

Btw it will be usefull to have the option for this in the plugin (w/o adding the permission in manifest by default or maybe as a plugin installation paramerter?).

I have multiple apps configured like this and for some Google ask for more for others not... (like Apple btw).

Thanks for the reply

HarelM commented 11 months ago

Yes, you don't need this permission. Also before Android 13 the icon was a must for running a foreground service, but in 13 the icon is not there by default, so over all I don't see how this permission is needed. Generally speaking, you can write a Cordova post install js script to add permissions, and in capacitor you can add those straight in the manifest, so I don't think a plugin parameter is truly needed here... But if this is important to you, feel free to open a PR.

oudoken commented 11 months ago

Hi @HarelM It's ok i think we can live without this permission switch. I wonder how the approval off app it's so different between apps that share an almost identical manifest btw. Thanks a lot Rob