Skip to content

Latest commit

 

History

History
117 lines (85 loc) · 5.08 KB

INSTALLATION.md

File metadata and controls

117 lines (85 loc) · 5.08 KB

Getting started

$ npm install react-native-google-fit --save

Note: If your React Native version > 0.60, You can skip the below section and scroll down to Demo Walkthrough Section to check how we config the authentication API with an existing project.

Enable Google Fitness API for your application

In order for your app to communicate properly with the Google Fitness API you need to enable Google Fit API in your Google API Console. Also you need to generate new client ID for your app and provide both debug and release SHA keys. Another step is to configure the consent screen, etc.

More detailed info available at https://developers.google.com/fit/android/get-api-key

1. In order for the library to work correctly, you'll need following SDK setups:
   
   Android Support Repository
   Android Support Library
   Google Play services
   Google Repository
   Google Play APK Expansion Library
   
2. 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.
   https://developers.google.com/fit/android/get-api-key

Mostly Automatic installation

$ react-native link react-native-google-fit

then pass your package name to the module in MainApplication.java (google fit requires package name to save data)

new GoogleFitPackage(BuildConfig.APPLICATION_ID) Note: Do not change BuildConfig.APPLICATION_ID - it's a constant value.

Manual installation

  1. Open up android/app/src/main/java/[...]/MainApplication.java

    • Add import com.reactnative.googlefit.GoogleFitPackage; to the imports at the top of the file
    • Add new GoogleFitPackage(BuildConfig.APPLICATION_ID), to the list returned by the getPackages() method. Note: Do not change BuildConfig.APPLICATION_ID - it's a constant value.
  2. Append the following lines to android/settings.gradle:

    include ':react-native-google-fit'
    project(':react-native-google-fit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-fit/android')
    
  3. Insert the following lines inside the dependencies block in android/app/build.gradle:

      compile project(':react-native-google-fit')
    

Note: If you are using the recording API for location/ distance data, you have to request the location-permission in your app's AndroidManifest.xml: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Demo Walkthrough

  1. npx react-native init AuthExampleTS --template react-native-template-typescript to create a fresh RN project then go into the project folder

  2. npm install react-native-google-fit --save install the library

  3. cd .\android\app in the root there is a debug.keystore file

    if you don't have one, then run (You need to enable keytool command in your machine)

   keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000

You can generate the file anywhere, just copy/paste it into .\android\app folder after creation

then run

   keytool -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android

Copy your SHA1: XX:XX:XX:XX:XX... for later use.

  1. https://developers.google.com/fit/android/get-api-key#request_an_oauth_20_client_id_in_the

Click Get a Client ID button , then Create a new Project for demonstration purpose.

Create credentials

  • 1). Credential Type
    Fitness API, check userdata
  • 2). OAuth Consent Screen
    Add your App name (it can be any but it will show up the name when asking authentication in your app)
    Add email
  • 3). Scopes (optional)
    Skip this part since we can ask permission in App.
  • 4). OAuth Client ID
    • Applicatin type: Android, it can be vary depends on your own app.
    • Name: Android client 1 for demo purpose
    • Package name:
      You can find your package name in AndroidManifest.xml under the android folder image
      in this demo it's com.authexamplets
    • SHA-1: SHA1: XX:XX:XX:XX:XX... you obtained previously
  • 5). Your Credentials
    Nothing you need to do.

After that, Go to your OAuth consent screen, there are two ways you can do

  • publish your app without verification to let everyone mess around
  • add test user email so your developed app can only be accessed by the test user only. image

Now add basic code into your app. You should be good to go.

image