Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@perfood/capacitor-google-fit
Advanced tools
Capacitor plugin to retrieve data from Google Fit
npm i --save @perfood/capacitor-google-fit
npx cap sync
In order for your app to communicate properly with the Google Fitness API, you need to provide the SHA1 sum of the certificate used for signing your application to Google. This will enable the GoogleFit plugin to communicate with the Fit application in each smartphone where the application is installed.
To do this:
Locate your debug keystore file. The file name is debug.keystore
List the SHA-1 fingerprint:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
The line that begins with SHA1 contains the certificate's SHA-1 fingerprint.
Go to the Google API Console
Create a project or choose existing project
Click Continue to enable the Fitness API.
Click Go to credentials
Now add credential to your project. Note that If this is the first time you configure the project you should "Configure the OAuth consent screen" first Click New credentials, then select OAuth Client ID.
Under Application type select Android.
In the resulting dialog, enter your app's SHA-1 fingerprint and package name. For example:
BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
com.example.android.fit-example
Click Create. Your new Android OAuth 2.0 Client ID and secret appear in the list of IDs for your project.
An OAuth 2.0 Client ID is a string of characters, something like this:
780816631155-gbvyo1o7r2pn95qc4ei9d61io4uh48hl.apps.googleusercontent.com
Register plugin inside your MainActivity
import com.adscientiam.capacitor.googlefit.GoogleFitPlugin;
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(GoogleFitPlugin.class);
}
import { Plugins } from '@capacitor/core';
const { GoogleFit } = Plugins;
Data Type | Unit | Google Fit equivalent |
---|---|---|
step | count | TYPE_STEP_COUNT_DELTA |
calories | kcal | TYPE_CALORIES_EXPENDED |
distance | m | TYPE_DISTANCE_DELTA |
weight | kg | TYPE_WEIGHT |
height | m | TYPE_HEIGHT |
activity | activityType | TYPE_ACTIVITY_SEGMENT |
Plugin method to connect to google fit service using user account. It will first check if the user has permissions to talk to Fitness APIs, otherwise authenticate the user and request required permissions.
A method which retrieve data from a specific time interval provided in parametre:
async getHistory() {
const today = new Date();
const lastWeek = new Date(today);
lastWeek.setDate(lastWeek.getDate() - 7);
const result = await GoogleFit.getHistory({
startTime: lastWeek,
endTime: today
});
console.log(result);
}
Same as getHistory() method but this time to retrieve activities Returned objects contain a set of fixed fields for each activity:
FAQs
Capacitor plugin to retrieve data from Google Fit
The npm package @perfood/capacitor-google-fit receives a total of 14 weekly downloads. As such, @perfood/capacitor-google-fit popularity was classified as not popular.
We found that @perfood/capacitor-google-fit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.