Android addAccountExplicitly 使用“com.google”类型
我从一开始就在寻找答案,但我仍然不知道该怎么办! 解释一下问题: 我的应用程序使用 GTasks API。为此,用户必须拥有谷歌帐户。我有两种方法来检查:
- 我实例化一个帐户管理器并查找“com.google”帐户(如果没有此类帐户)
- 我启动一个网络视图,用户在该视图上登录 Google 并接受使用 API。
然后,我必须将我的应用程序与 GTask 同步。 根据从网络视图中提取的信息,我尝试使用 AccountManager 创建一个“com.google”帐户,但总是出现错误“呼叫者 UID 不同...”。我知道问题应该来自“account-authenticator”,因为“accountType”在 XML 文件和应用程序中必须相同,但我认为情况并非如此,因为当我使用不同的帐户类型时,它可以完美工作(但我无法从 GTask 获取 authToken)。
所以,这是我的代码:
Authenticator.xml:
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.google"
android:icon="@drawable/miniicon"
android:smallIcon="@drawable/miniicon"
android:label="@string/app_name"
android:accountPreferences="@xml/preferences"
/>
帐户类型的定义:
public class AuthenticationService extends Service {
public static final String ACCOUNT_TYPE = "com.google";
我如何在课堂上使用它:
AccountManager manager = AccountManager.get(activity);
final Account account = new Account(login, AuthenticationService.ACCOUNT_TYPE);
manager.addAccountExplicitly(account, password, new Bundle());
当我使用“com.plop”或其他任何东西而不是“com.google”时,它工作得很好。
所以,我的两个问题是: 1. 我可以使用“com.google”帐户类型吗? 2.我无法使用“com.google”以外的其他东西获取我的authToken,这正常吗(知道使用的帐户仍然是Google帐户,只是在Android上没有这样设置)?
提前感谢您的帮助,如果答案在网站上,请原谅我!
I'm looking for the answer since the begining of the day and I still don't know what to do!
To explain the problem:
My application uses GTasks API. To do this, the user MUST have a google account. I have two ways to check that:
- I instantiate an Account manager and look for "com.google" accounts if there are no such accounts
- I launch a webview on which the user logs on Google and accepts to use the API.
Then, I have to synchronize my application with GTask.
From the information extracted from the webview, I tried to create a "com.google" account using the AccountManager but I always have the error "Caller UID is different...". I know that the problem should come from "account-authenticator" because the "accountType" has to be the same in the XML file and in the app but I think that's not the case because when I use a different account type, it perfectly works (but I can't obtain an authToken from GTask).
So, here is my code:
Authenticator.xml:
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.google"
android:icon="@drawable/miniicon"
android:smallIcon="@drawable/miniicon"
android:label="@string/app_name"
android:accountPreferences="@xml/preferences"
/>
Definition of the account type:
public class AuthenticationService extends Service {
public static final String ACCOUNT_TYPE = "com.google";
How I use it in my class:
AccountManager manager = AccountManager.get(activity);
final Account account = new Account(login, AuthenticationService.ACCOUNT_TYPE);
manager.addAccountExplicitly(account, password, new Bundle());
When I use "com.plop" or anaything else instead of "com.google", it works really fine.
So, my two questions are:
1. Can I use the "com.google" account type?
2. Is that normal that I can't obtain my authToken using something else than "com.google" (knowing that the account used is still a Google account, it's just not set like that on Android) ?
Thx in advance for your help and, please, forgive me if the answer was on the site!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我回答了我自己的问题:这不可能是我想要的。您必须使用“com.google”帐户类型来使用“addAccount”功能。这将导致弹出 Android 系统使用的帐户创建活动。然后,使用 GTasks API 一切都很好。
I answered my own question: that's not possible the way I wanted to. You have to use the "addAccount" function using a "com.google" account type. This will result in popping the account creation activity used by the android system. Then, everything is fine using GTasks API.