How to add google account in android via AccountManager.addaccountExternally ()?

I want to add google account explicitly. I will provide a username and password.

I just went through this question caller uid XXXX is different from the authenticator UID But I did not get a solution. What is uid? to which he compares.

I'm trying to

AccountManager mgr = (AccountManager)getSystemService(ACCOUNT_SERVICE); Account acc = new Account(" xxxj@gmail.com ", "com.google"); if(mgr.addAccountExplicitly(acc, "Password", new Bundle())) { //account added successfully //do whatever is needed; showToast("added"); } else { //something did not work } 

Error: Caller uid 10782 is different from the uid authenticator.

What does it mean? How can I fix it?

Someone tell me how to solve this complete code would be very helpful.

0
source share
1 answer

UID is the user identifier assigned to your application. Each application has its own UID , but if you create several applications yourself, you can make them share the same UID .

An authenticator is a module that processes and authenticates accounts belonging to this authenticator. Thus, Google authenticator is used to process Google accounts, and "authenticator X" is used to process "X accounts."

AddAccountExplicitly is a method that is intended to be used when creating accounts of your own type using your own authenticator. The documentation for AddAccountExplicitly says:

This method requires the caller to have AUTHENTICATE_ACCOUNTS permission and have the same UID as the authenticator account added.

The only way the calling application UID and authenticator UID can be the same is to create both the calling application and the account authenticator.

In other words, it is not possible to add / create a Google account using addAccountExplicitly() . You can add accounts only for your own services.

Depending on what you want to do, perhaps you can show the Add Account dialog box to the user and allow the user to add an account on their own: Programmatically launch the Add Account activity in Android 2.2

Or maybe you can use the Admin SDK directory APIs to create accounts that can be used with Google services, but this is not a Google account: Can I create a Google account programmatically?

+6
source

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


All Articles