I am following this tutorial to integrate Google Fit API
Steps that I did:
The Google sign-in request is always failing. Sharing the code below.
private fun connectToGoogleFit() {
Log.e("GOOGLE_FIT", "google fit init")
val fitnessOptions = FitnessOptions.builder()
.addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
.addDataType(DataType.AGGREGATE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
.build()
if (!GoogleSignIn.hasPermissions(
GoogleSignIn.getLastSignedInAccount(this),
fitnessOptions
)
) {
Log.e("GOOGLE_FIT", "no permission")
GoogleSignIn.requestPermissions(
this, // your activity
GOOGLE_FIT_PERMISSIONS_REQUEST_CODE,
GoogleSignIn.getLastSignedInAccount(this),
fitnessOptions
)
} else {
Log.e("GOOGLE_FIT", "has permission")
accessGoogleFit()
}
}
private fun accessGoogleFit() {
//todo
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == GOOGLE_FIT_PERMISSIONS_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
Log.e("GOOGLE_FIT", "connection success")
accessGoogleFit()
} else {
Log.e("GOOGLE_FIT", "connection failed")
}
}
}
I can see an account selector dialog on running this code. I get the failure code in onActivityResult on selecting an account from the dialog.
The available docs seem to be very old. Did I miss anything?
i had the same problem.
After more than a day i figure out the solution.
In order to use Google Fit you must enable Google Provider in Authentication panel of your Firebase Project.