【发布时间】:2021-08-05 19:43:26
【问题描述】:
总结
我有一个 Xamarin 应用程序,它创建一个 GoogleApiClient 并调用 EnableAutoManage。当我的应用程序运行时,系统会询问我要使用哪个用户帐户,然后应用程序会挂在带有 Google 主题微调器的空白弹出页面上。为什么会这样?
详情
我一直在关注这个视频,它展示了如何设置应用程序来读取 Google Fit 数据。注意时间戳 - 这是显示代码的地方。
https://youtu.be/j_zsNxMI6jI?t=2172
我已经按照这里的例子,并将问题缩小到这段代码:
// In my MainActivity's OnCreate:
try
{
int defaultClientId = 0;
googleApiClient = new GoogleApiClient.Builder(this)
.AddApi(FitnessClass.HISTORY_API)
.AddApi(FitnessClass.RECORDING_API)
.AddScope(FitnessClass.ScopeActivityRead)
.EnableAutoManage(this, defaultClientId,
result =>
{
int m = 3; // Breakpoint here is never hit
})
.Build();
}
catch (Exception e)
{
int m = 3; // Breakpoint here is never hit either
}
如果我运行我的应用程序(在模拟器和物理硬件上都试过),首先会询问我要使用哪个帐户。
选择帐户后,会出现另一个弹出窗口,顶部带有一个以 Google 为主题(在红色、黄色、绿色和蓝色之间切换)的微调器。弹出窗口停留在屏幕上,并且微调器无限期地动画。
如上面的代码中所述,不会引发异常,也不会在 EnableAutoManage 委托中返回任何结果。为什么会这样?
更新 1
如果我删除以下行,应用将不再无限期地显示微调器:
.AddScope(FitnessClass.ScopeActivityRead)
这行代码的添加似乎是微调器弹出的原因。
更新 2
我想我会尝试使用 GoogleApi 而不是 GoogleApiClient 的“新”方法,如下所述:
https://android-developers.googleblog.com/2017/11/moving-past-googleapiclient_21.html
不幸的是,目前似乎还没有 Xamarin 绑定:
Xamarin Android: Cannot resolve GoogleSignIn and GoogleSignInClient
【问题讨论】:
标签: c# android xamarin google-api-client