Michal
Michal

Reputation: 6693

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?

Upvotes: 1

Views: 1493

Answers (1)

pablisco
pablisco

Reputation: 14237

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.

Upvotes: 1

Related Questions