因此,我正在尝试使用 Google Fit,但由于某种原因,我无法在我的应用中连接到 Google Play 服务。我已经完全设置了 OAuth,并在另一个应用程序中对其进行了测试,一切正常。具体看看 GoogleFitRepository,这是我连接到 API 的地方。
尝试连接时出现此错误:
W/AutoManageHelper: Unresolved error while connecting client. Stopping auto-manage.
I/MyApp: Google Play services connection failed. Cause: ConnectionResult{statusCode=CANCELED, resolution=null, message=null}
GitHub链接:https ://github.com/drb56/FitnessExplorer
任何帮助将不胜感激。我整天都被困在这上面!
编辑:这是相关课程中的一些代码
public GoogleFitRepository(Activity activity)
{
mClient = new GoogleApiClient.Builder(activity.getApplicationContext())
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addConnectionCallbacks(this)
.enableAutoManage((FragmentActivity)activity, 0, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i("MyApp", "Google Play services connection failed. Cause: " +
result.toString());
}})
.build();
activityList = new ArrayList<>();
activityDataPointList = new ArrayList<>();
calorieActivitiesToday = new ArrayList<>();
dayActivities = new ArrayList<>();
}