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

Remove steps from dataTypes array if Activity Permissions are not gra… #336

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,38 @@ class RNGoogleFit {
return dataTypes.filter(data => data !== 'distance');
}
} catch (err) {
console.warn(err);
};
console.warn(err)
}
}
return dataTypes;
const activityRecognitionPermission = await PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.ACTIVITY_RECOGNITION
)
if (dataTypes.includes('step') && !activityRecognitionPermission) {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACTIVITY_RECOGNITION,
{
title: 'Access Physical Activity Permission',
message:
'Enable physical activity access for Google Fit Api. ' +
'Cancel may cause inaccuracy result',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
}
)

// this need to be changed in the future if we want to use RecordingAPI for more sensitive permissions
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// we don't do anything here since the permission are granted
} else {
// remove step from array to avoid crash,
return dataTypes.filter((data) => data !== 'step')
}
} catch (err) {
console.warn(err)
}
}
return dataTypes
}

/**
Expand Down Expand Up @@ -1070,4 +1098,4 @@ export const ActivityTypeCode = Object.freeze({
Windsurfing: 99,
Yoga: 100,
Zumba: 101
})
})