androidgoogle-fitgoogle-fit-sdkuser-identification

How to find which account (email) has user used to log into my google-fit based android app?


I am trying to make an android app based on google-fit.

What I am trying to achieve is that I create an account for the user on my website as soon as the user chooses an account using the app.

Here is the code base that I want to build up upon (It is just the basic registration sample code) https://github.com/ishanatmuz/GoogleFitTest/tree/829051b7739ee9d8871c3ba9e5f21dfb17f4f3d7

onConnected is called when the user has succesfully signed in and provided the permissions. I am calling my own function to do further work which is basically this :

  1. Get the information (at least email) of the user who just signed in.
  2. Send the user to my server for registration.
  3. Continue with the rest of the app.

I need help figuring out how to do the step 1.

Any help will be greatly appreciated.


Solution

  • On your onConnected() method, you can get it with:

    Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
    String personName = currentPerson.getDisplayName();
    String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);