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

Address new ACTIVITY_RECOGNITION Android permission #178

Closed
VladKozlov368 opened this issue Jun 15, 2020 · 15 comments
Closed

Address new ACTIVITY_RECOGNITION Android permission #178

VladKozlov368 opened this issue Jun 15, 2020 · 15 comments

Comments

@VladKozlov368
Copy link

There was a problem that on some devices we can't receive data from Google Fit. For example, in Xiaomi Mi 8, android 10, we always get the error com.google.step_count.delta requires android.permission.activity_recognition. All stages of authorization have been completed and permissions have been given everywhere to receive data: ['steps', 'weight', 'blood_pressure', 'heart_rate']. In config.xml are written: HEALTH_READ_PERMISSION, HEALTH_WRITE_PERMISSION

But this error is rarely shown, and on many devices, after authorization, we can correctly get the data.

Has anyone encountered this problem?

@dariosalvi78
Copy link
Owner

looks like something new introduce by Android 10. The permission is automatically granted if you target Android 9 or lower, which may fix it temporarily. For future implementations, it would be better to include this when requesting permissions for these specific data sets.

Very happy to receive PRs in this regard.

@dariosalvi78 dariosalvi78 changed the title It isn't possible to receive data on some devices Address new ACTIVITY_RECOGNITION Android permission Jun 15, 2020
@VladKozlov368
Copy link
Author

@dariosalvi78 yes it works for me, thanks!

For 10 android need to do the following:

step 1: add plugin android permissions

ionic cordova plugin add cordova-plugin-android-permissions
npm install @ionic-native/android-permissions

step 2: go to the config.xml file in the root folder and add:

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

step 3: request permissions ACTIVITY_RECOGNITION and then perform the necessary actions...

constructor(private _androidPermissions: AndroidPermissions) {
    this._androidPermissions.requestPermission('android.permission.ACTIVITY_RECOGNITION')
        .then(result => {
            console.log(result.hasPermission);
            // Authorize using the requestAuthorization method in health plugin
        })
        .catch(console.error);
}

@dariosalvi78
Copy link
Owner

I want to keep this open as the solution should be included in the plugin.

@dariosalvi78 dariosalvi78 reopened this Jun 18, 2020
@gasci
Copy link

gasci commented Oct 8, 2020

Great plugin! Has the problem with steps regarding the Android 10 permission been solved?

@dariosalvi78
Copy link
Owner

I've been going through this: the current cordova android support targets API version up to 28 (Android 9). This makes it impossible to use the new permissions on a regular cordova project. How did you get into this problem?

@gasci
Copy link

gasci commented Oct 13, 2020 via email

@gasci
Copy link

gasci commented Oct 13, 2020 via email

@gasci
Copy link

gasci commented Oct 13, 2020 via email

dariosalvi78 added a commit that referenced this issue Oct 15, 2020
Removed deprecated APIs, uses new Android 10 auth model, removed DOB and gender.
Solves #178 solves #170.
@dariosalvi78
Copy link
Owner

this should be solved now. I haven't tested this thoroughly, so, before releasing a new version, I would appreciate a confirmation that this is working in your app(s). Please be aware that I have removed DOB and gender from Fit (didn't make sense) and that you will need to activate AndroidX if you use the latest Android platform (see README for that).

@gasci
Copy link

gasci commented Oct 15, 2020 via email

@gasci
Copy link

gasci commented Oct 15, 2020 via email

@dariosalvi78
Copy link
Owner

what data type are you trying to access concretely?

@gasci
Copy link

gasci commented Oct 15, 2020 via email

@dariosalvi78
Copy link
Owner

I have tested distance, calories and steps independently and they are working on my phone. I have found a little bug anyway so I recommend you pull the latest version and try again.
For faster communication, I would suggest using the official chat.

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

3 participants