简体   繁体   中英

Creating a google account on android programatically (non-rooted device)

I need to create (or associate) a google account on my android device. I have enabled USB-debugging, and I am able to run commands through adb (USB-debugging enabled). I have tried several approaches and searched, but I have not been able to come up with a solution.

I know that you are able to delete a google account with the permission MANAGE_ACCOUNTS, this is one of the reasons why I need to be able to automatically add the account. When simply using addAccountExplicitly with the namespace com.google, it gives me the error "java.lang.SecurityException: caller uid 10165 is different than the authenticator's uid" which is described in the android developer documentation.

Cheers

You can try using the AccountManager addAccount method.

AccountManager accountMgr = AccountManager.get(mContext);
accountMgr.addAccount("com.google", "Auth_Token_Type", null, new Bundle(), (Activity) mContext, null, null);

For the auth token type you may be able to use "oauth2: https://mail.google.com/ "

Alternatively, you can use the native device Add Account intent by doing

startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));

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