开发者

Adding in application Google Account using AccountManager

I'm trying to add functionality in my application, that add a google account to Android Account Manager, by use of method

mAccountManager = AccountManager.get(getBaseApplicationContext());

Account account = new Account("sample.account", "com.google");

开发者_如何学运维 ac.addAccountExplicitly(account, "password", null);

But it indicates an exception

java.lang.SecurityException: caller uid 10117 is different than the authenticato r's uid

Is it possible to add account in application code (being more precisely logging to already existing google account)? Which method should I use?


You need to use the same UID as the account type but you can't sign your app with the package (it get's translated into the UID) "com.google".

You can get the Accounts available using:

manager.getAccountsByType("com.google"); // returns array

or with API level 14 you can call:

AccountManager.newChooseAccountsIntent(null, null, new String[]{"com.google"}, false, null, null, null, null);

If you want it on earlier versions you can get the source code and implement the same mechanics in your project.

The only option to add a Google account would be to get the intents that are sent when the login Activity is sent and try to send the same intent to ask the user to input the account. Once in you can get the details with the method I've mentioned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜