Google 帐户身份验证器在运行时请求许可

发布于 2024-10-29 06:31:57 字数 884 浏览 8 评论 0原文

我使用服务中的 AccountManager.getAuthToken 来访问 Googledocs 和 Spreadsheet API。

由于我是从后台执行此操作并且不想中断 user ,因此我允许 accountManager 在需要用户交互时发出通知(使用参数布尔 notifyAuthFailure )。

正如我所料,CallBack 是通过 AccounManagerFuture 调用的,在这种情况下它会解析为带有 KEY_INTENT 字段的 Bundle。

“在这种情况下,您可能需要等待 直到用户响应,这可以 需要几个小时、几天或永远。什么时候 用户确实响应并提供了新的 密码,客户经理会 广播 LOGIN_ACCOUNTS_CHANGED_ACTION 意图, 哪些应用程序可以使用来尝试 再次”

它工作得很好,当事情只是关于错误的密码时。但是我遇到了一个问题,AccountAuthenticator在运行时请求许可并且意图(从通知栏)启动GrantCredentialsPermissionActivity,在用户按下按钮(允许或拒绝)后执行不允许我知道用户已经响应。

问题是如何知道与用户的交互何时完成并再次尝试获取 AuthToken

我无法从 GrantCredentialsPermissionActivity 获取 onActivityResult 因为我是从NotificationBar(而不是从我的其他活动)启动它 。 ,因为我在尝试获取令牌时使用服务)

我无法在清单中指定权限,因为据我了解,这是由谷歌身份验证器定义的一些自定义权限,

当用户批准/拒绝时,它似乎没有广播任何意图。关闭 GrantCredentialsPermissionActivity 后在运行时请求应用程序的权限。 谢谢。

I use AccountManager.getAuthToken from my service to have access to Googledocs and Spreadsheet API.

As I'm doing it from background and don't want to interrupt user , I allow accountManager to raise notification when user interaction needed (using parameter boolean notifyAuthFailure).

As I expected, CallBack is called with AccounManagerFuture,which resolves to Bundle with KEY_INTENT field in such case.

"In that case, you may need to wait
until the user responds, which could
take hours or days or forever. When
the user does respond and supply a new
password, the account manager will
broadcast the
LOGIN_ACCOUNTS_CHANGED_ACTION Intent,
which applications can use to try
again"

It works well, when thing is only about a wrong password. But I run in a problem,that AccountAuthenticator asks for permision at runtime and intent (from notification bar) starts GrantCredentialsPermissionActivity, which after user presses button (Allow or Deny) do not allow me get know that user already responded.

The question is how to get know when interection with user is finished and try again to get AuthToken.

I cant't get onActivityResult from GrantCredentialsPermissionActivity because I start it from NotificationBar (not from my other activity, as I use service while trying to get token)

I can't specify permissions in manifest beforehead, because as i understand it's some custome permissions, which defined by google authenticator.

It doesn't seem to broadcast any intent when user approve/deny requested permission for application at run-time after closing GrantCredentialsPermissionActivity.
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不及他 2024-11-05 06:31:57

只需再次检查 onResume 即可调用,即使权限活动是一个对话框。你的要求会超出需要,但又不过分。

Just check again in onResume that will get called even if the permission activity is a dialog. You will be asking more than needed but not excessively.

尐籹人 2024-11-05 06:31:57

我认为了解用户交互何时完成的最佳方法是广播事件并接收它。

What I think would be the best way to know when user interaction is finished is to BroadCast an event and receive it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文