Reputation: 151
I am trying to build a bpm counter for my thesis project. I am a novice regarding Google Fitness Api, so I started by cloning google's step counter sample from git. (Link if interested [here][1]). I set everything up, I authorised my account, connected it to a cloud project, used keytool for an SHA-1 cert, but I still cannot get a Response with the data I ask for, where it is bpm or steps. I set every permission as needed in the xml file and still face the issue. Below, I give you some parts of my code, if you need anything else lmk. Thanks in advance for any responses.
XML Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
SignIn Function:
private fun fitSignIn(requestCode: FitActionRequestCode) {
if (oAuthPermissionsApproved()) {
performActionForRequestCode(requestCode)
} else {
requestCode.let {
GoogleSignIn.requestPermissions(
this,
requestCode.ordinal,
getGoogleAccount(), fitnessOptions)
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (resultCode) {
RESULT_OK -> {
val postSignInAction = FitActionRequestCode.values()[requestCode]
postSignInAction.let {
performActionForRequestCode(postSignInAction)
}
}
else -> oAuthErrorMsg(requestCode, resultCode)
}
}
Code Request when selecting my GAccount:
private fun performActionForRequestCode(requestCode: FitActionRequestCode) = when (requestCode) {
FitActionRequestCode.READ_DATA -> readData()
FitActionRequestCode.SUBSCRIBE -> subscribe()
}
private fun oAuthErrorMsg(requestCode: Int, resultCode: Int) {
val message = """
There was an error signing into Fit. Check the troubleshooting section of the README
for potential issues.
Request code was: $requestCode
Result code was: $resultCode
""".trimIndent()
Log.e(TAG, message)
}
private fun oAuthPermissionsApproved() = GoogleSignIn.hasPermissions(getGoogleAccount(), fitnessOptions)
private fun getGoogleAccount() = GoogleSignIn.getAccountForExtension(this, fitnessOptions)
I always end up with a result 0 when requesting data.
[![emulator][2]][2]
And here is my cloud settings for my account. [![GCloud][3]][3]
I have triple-checked that everything is done correctly from Google Fit's FAQ and that I have the Fitness Api enabled for my project, but I still don't get any steps as a result. I would be grateful if anyone could point me to the right direction. Thanks in advance [1]: https://github.com/android/fit-samples/tree/master/StepCounterKotlin [2]: https://i.sstatic.net/zvTni.png [3]: https://i.sstatic.net/UbtPb.png
Upvotes: 1
Views: 899
Reputation: 151
Answering my own question. After 4 dys of agonizing searching, the solution was far too simple. Android Studio by itself when deploying debug apks, uses a debug.keystore file. In order to change that to the file that you used to sign your SHA-1. To do that, Go to:
File->Project Structure->Modules->App->Signing Configs and edit the debug config to use your keystore file that you created. Input the password and the alias and rebuild your apk. This time the Fit Api will connect!
Upvotes: 1