Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permission issue on android X #170

Open
dpsa-dev opened this issue Nov 20, 2023 · 9 comments
Open

permission issue on android X #170

dpsa-dev opened this issue Nov 20, 2023 · 9 comments

Comments

@dpsa-dev
Copy link

Hi there

And thanks for the plugin and your time

The plugin is working pretty great on my Android 9 device,
but when I want to test on my other device with Android 11 it crashes when calling the start function and I see the below

java.lang.SecurityException: Activity detection usage requires the ACTIVITY_RECOGNITION permission

To reproduce:

Install on device with Android 11
Run the start() function

Used on a Cordova version 12 app with

I have found online the following solution which makes the error go away but location tracking not starting as expect
--also this additonal code makes the code stop working on device 1 with Android 9

public static final String[] PERMISSIONS = {
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.ACCESS_FINE_LOCATION
};

changed to

public static final String[] PERMISSIONS = {
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.ACCESS_FINE_LOCATION,
        Manifest.permission.ACTIVITY_RECOGNITION
};
@HarelM
Copy link
Collaborator

HarelM commented Nov 20, 2023

The plugin is targeting Android 13, so you might need to use older version of the plugin, IDK.
I suggest to try and debug it using Android studio and do the relevant changes accordingly...

@dpsa-dev
Copy link
Author

dpsa-dev commented Nov 20, 2023

Thanks for getting back:) that seldom happens hehe

Idk either I added a permission plugin for cordova
https://www.npmjs.com/package/cordova-plugin-android-permissions

I dont think that helped, I think the below manifest entry did the job:

//this was already there...auto added by cordova /build
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
//added this additionally........?
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" /> <------

@HarelM
Copy link
Collaborator

HarelM commented Nov 20, 2023

If it helped then that's great!

@bsprengelmeijer
Copy link

bsprengelmeijer commented Dec 7, 2023

I'm having the same issue, did you solve it already @dpsa-dev ?

I've tried asking for the permission before starting the service but it's not working

/edit nevermind I now see your comment about the added permission in the manifest. This also did the trick for me

@dpsa-dev
Copy link
Author

dpsa-dev commented Dec 7, 2023

I had to install a extra Cordova plugin in the end that was the only way to get it going:
"cordova-plugin-android-permissions": "1.1.5",
and then it should ask for the permission permissions.ACTIVITY_RECOGNITION
which opens a popup window for the user asking permissions

and the below

Hope it helps

 var permissions = cordova.plugins.permissions;

        permissions.requestPermission(permissions.ACTIVITY_RECOGNITION, success, error);

        function error() {
            //alert('ACTIVITY_RECOGNITION is not turned on');
        }

        function success( status ) {
            
            BackgroundGeolocation.configure({
                locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
                desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
                stationaryRadius: 50,
                distanceFilter: 50,
                notificationTitle: 'Background tracking',
                notificationText: 'enabled',
                interval: 10000,
                debug: false,
                fastestInterval: 5000,
                activitiesInterval: 10000,
                url: `${baseUrlApi}update-live-share`,
                httpHeaders: {
                'X-FOO': 'bar'
                },
                // customize post properties
                postTemplate: {
                    "client" : CURRENT_CLIENT_ID,
                    "session" : CURRENT_TOKEN,
                    "liveShare" : CURRENT_MY_LIVE_SHARE_ID,
                    "latitude" : "@latitude",
                    "longitude" : "@longitude",
                    "accuracy" : CURRENT_ACCURACY 
                }
            });
            
            try {
                startTrackerTrack();
            } catch (e) { console.log(e); }
        }

@Jurfix
Copy link

Jurfix commented Jan 21, 2024

Hello, I have Android 13, I use the full code from the example, and when I enable the use of GPS, the application crashes with the error:
java.lang.SecurityException: Activity detection usage requires the ACTIVITY_RECOGNITION permission
I added what you recommended to the manifest, but nothing changed:
image

I also tried using the permission plugin, but it doesn’t even come with a request for GPS permission.
If someone can help it would be great.

upd: So, I was still able to solve the problem using a permission request and a permissions plugin

@dpsa-dev
Copy link
Author

dpsa-dev commented Jan 22, 2024

In the end I had to do both the fixes above for it to work,
eg 1. install the Cordova permission plugin and ask for permission before executing the navigation/geo code
and 2. the manifest needs a extra line (which is still weird) <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

when the permission plugin code is executed it should pop up a window on the app asking for activity permission,
thats was for getting it to work on Android 12

Unless android 13 has new changes but I had the same general error message that permission missing

@risinghero
Copy link

To add extra line to manifest it's better to use config.xml like so:

<platform name="android">
        <config-file parent="/manifest" target="AndroidManifest.xml"
            xmlns:android="http://schemas.android.com/apk/res/android">
            <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
        </config-file>
    </platform>

@dpsa-dev
Copy link
Author

I added it in the manifest file, just underneath the existing one which is <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants