简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM