Setting up Google phone Account programmatically
-
03-07-2021 - |
Pregunta
I am interested in adding and setting up a hard-coded Google Account with a given username and password programmatically on the phone without any user intervention.
I have tried using
AccountsManager.addAccountExplicitly(newAccount("xxxxxx@gmail.com","com.google",password,null)
It works perfectly for all the accountsType
except for the com.google accountsType
throwing the "uid not matching authenticator
id" exception.
I have already followed all the suggestions given in this particular thread for fixing the error but of no use, the error persists for com.google accounts type
SecurityException: caller uid XXXX is different than the authenticator's uid
The other alternative approach I tried was using the samplesyncadapter
code, it works perfectly fine, the authentication part is done in NetworkUtilities
file which I believe need to be changed to Google accounts clientlogin
Is there anyway this can be performed directly without user intervention for captcha??
Solución
OK after few months, I managed to solve this issue. Might be helpful to someone.
The solution is not generic but quite specific to emulator/device LCD characteristic and ugly.
I used MonkeyRunner to issue touch, press and key events at specified screen coordinates to reach Home->Apps->Settings->Accounts and Sync->Add Account->Google->Next->Sign In and so on
More details about MonkeyRunner can be found here
http://developer.android.com/tools/help/monkeyrunner_concepts.html