【问题标题】:Why does GoogleApiClient.Build.EnableAutoManage softlock my application?为什么 GoogleApiClient.Build.EnableAutoManage 软锁定我的应用程序?
【发布时间】: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


    【解决方案1】:

    发生这种情况的原因是我的 Google 帐户尚未添加为测试用户。人们可能期望 Google 会通过弹出窗口提供某种有用的反馈,但它提供了一个空白页面。

    解决这个问题:

    1. 转到https://console.cloud.google.com/apis/dashboard
    2. 点击 OAuth 同意屏幕
    3. 向下滚动到测试用户部分
    4. 输入您希望用来测试您的应用的测试用户的电子邮件地址(例如您自己的个人 gmail)

    现在应用应该正确显示确认页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      相关资源
      最近更新 更多