AccountManager 阻止GetAuthToken 被卡住
我一直在使用 SampleSyncAdapter 作为创建我自己的 SyncAdapter 的基础。添加新帐户似乎效果很好,但是一旦我想使用 AccountManager.blockingGetAuthToken(... 获取 authtoken,它就会卡住,然后在几分钟后抛出 OperarationCanceledException。
有人知道可能出了什么问题吗这里的代码几乎与示例相同,只是我正在向我自己的服务器进行身份验证
:ERROR/SyncAdapter(4961):OperationCanceledExcetpion。 05-24 23:00:23.258:错误/SyncAdapter(4961):android.accounts.OperationCanceledException 05-24 23:00:23.258: 错误/SyncAdapter(4961): 在 android.accounts.AccountManager$AmsTask.internalGetResult(AccountManager.java:1255) 05-24 23:00:23.258: 错误/SyncAdapter(4961): 在 android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1260) 05-24 23:00:23.258: 错误/SyncAdapter(4961): 在 android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1181) 05-24 23:00:23.258:错误/SyncAdapter(4961):在android.accounts.AccountManager.blockingGetAuthToken(AccountManager.java:737)
I've been using the SampleSyncAdapter
as a base to create my own SyncAdapter. It seems to work well to add a new account, but once I want to get the authtoken with AccountManager.blockingGetAuthToken(... it gets stuck and then throws an OperarationCanceledException after a few minutes.
Does anyone have an Idea of what could be wrong here? The code is almost the same as the sample except I am authenticating towards my own server.
05-24 23:00:23.258: ERROR/SyncAdapter(4961): OperationCanceledExcetpion
05-24 23:00:23.258: ERROR/SyncAdapter(4961): android.accounts.OperationCanceledException
05-24 23:00:23.258: ERROR/SyncAdapter(4961): at android.accounts.AccountManager$AmsTask.internalGetResult(AccountManager.java:1255)
05-24 23:00:23.258: ERROR/SyncAdapter(4961): at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1260)
05-24 23:00:23.258: ERROR/SyncAdapter(4961): at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1181)
05-24 23:00:23.258: ERROR/SyncAdapter(4961): at android.accounts.AccountManager.blockingGetAuthToken(AccountManager.java:737)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
blockingGetAuthToken
方法是同步调用getAuthToken
的帮助程序。如果您正在访问网络来检索身份验证令牌,您将被阻止,直到请求成功。您应该检查是否可以从应用程序内正确访问网络资源。
The
blockingGetAuthToken
method is a helper that callsgetAuthToken
synchronously.If you are accessing the network to retrieve the auth token you will be blocked until the request succeeds. You should check that you can access the network resource properly from within your application.
原本方法是一种获取 authtoken 的便捷方法,而不是调用方法 getAuthToken。
必须通过调用 runOnUIthread 方法来确保不在主线程中。或者您可以调用默认方法 getAuthToken 并使用回调来执行下一条指令。例如。
originally method is a convenient way to get authtoken instead calling method getAuthToken.
have to make sure not in the mainthread by calling methed runOnUIthread. or you can call the default method getAuthToken and using callback for execute next instruction. for the example.