Registering Google programs on an Android device

I have been looking for a solution to this problem for a while (days, not minutes), but it eludes me quite effectively.

Please note that this is NOT a question of starting the registration procedure. This should happen automatically without any user interaction.

I would like to add a Google account to my user device (1000 of them). The account will be used primarily to activate the Google Play store on the device so that the application can be updated when newer versions are available.

My existing code (the shortest snippet I've tried):

AccountManager mgr = AccountManager.get(this); Account acc = new Account(" email@gmail.com ", "com.google"); mgr.addAccountExplicitly(acc, "password", new Bundle())); 

naturally gives a

 java.lang.SecurityException: caller uid 10047 is different than the authenticator uid 

So how can I do this? My device is rooted so that it’s not an obstacle if this is the only way.

+5
source share
2 answers

Well, as it turned out, this is not so easy to solve. I finished registering one device, and then pulled out a user file from it. Location of the user file: /data/system/users/0/accounts.db (if the device has several user profiles, the last directory may differ depending on the profile).

I saved this file in my application assets (gzipped, make sure that the extension is not something. Gz, because it is lost during packaging - I did not bother to check why).

First I check if my user exists:

 AccountManager mgr = AccountManager.get(this); for (Account acc: mgr.getAccountsByType("com.google")) { if (acc.name.equalsIgnoreCase(" email@gmail.com ")) return; } 

If so, I will just skip the step. Otherwise, I will unzip the user file and overwrite the existing one (using su ). Then I also reboot to make sure the changes are logged.

0
source

Unable to add / create google account using addAccountExplicitly (). You can add accounts only for your own services. even your device is rooted because it will be rejected by the Google web server. See link for more details.

0
source

Source: https://habr.com/ru/post/1238958/


All Articles