3

I have an app that needs to access Google Fit Api.
I can get the google sign-in pop up. But the next screen, requesting permission for my data types (TYPE_STEP_COUNT_DELTA, AGGREGATE_STEP_COUNT_DELTA) is not displayed.

As soon as I choose my google account the pop-up goes away and nothing is displayed further.

enter image description here

I have followed all the steps for the Setup mentioned here https://developers.google.com/fit/android/get-started

  1. Set up my project in Google API developer console

  2. Install google play services packages in my android studio

  3. Created an OAuth 2.0 Client ID enter image description here

  4. Add the dependencies

  dependencies {
        implementation 'com.google.android.gms:play-services-fitness:20.0.0'
        implementation 'com.google.android.gms:play-services-auth:19.0.0'
    }
  1. Enable sign-in options "google" in my firebase console

Yet I do not get the further screens.

My code is as below:

 public void setFitnessOption() {
        fitnessOptions =
                FitnessOptions.builder()
                        .addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
                        .addDataType(DataType.AGGREGATE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
                        .build();
      }

public void checkFitInstalled() {
        if (isGoogleFitPermissionGranted()) {
            GetData();  //step count query       
        } else {
          requestGoogleFitPermission();
            GetData();    //step count query
        }
      }

public boolean isGoogleFitPermissionGranted() {
        if (GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), fitnessOptions)) {
          return true;
        } else {
          return false;
        }
      }

public void requestGoogleFitPermission() {
        GoogleSignInAccount account = GoogleSignIn.getAccountForExtension(this, fitnessOptions);
        GoogleSignIn.requestPermissions(
                this,
                GOOGLE_FIT_PERMISSIONS_REQUEST_CODE,
                account,
                fitnessOptions);
      }


What am I missing out?? struggling for days with this issue. Any input would be great!!!

grooot
  • 446
  • 2
  • 10
  • 31
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Jeroen Steenbeeke Jan 29 '21 at 07:29
  • The probblem is with your `reactApplicationContext`, it is null. Check your `ReactModule`. – Lalit Fauzdar Feb 01 '21 at 03:46
  • @Lalit In my ReactModule I tried a simple method that returns "Hello World" to my front-end. It worked and it I could load my reactApplicationContext. My guess is my connectivity between ReactModule and MainActivity() is not correct. – grooot Feb 01 '21 at 04:31

1 Answers1

1
  1. Go to Google Cloud Platform.
  2. In the left panel of your project, select OAuth Consent Screen.
  3. Scroll down and you'll see Test Users. Here, add the email address of the user. Hope it works for you.
Arel Guatno
  • 872
  • 9
  • 13