0

I want to add a google account Explicitly. I will provide username and Password.

I just Gone through this Question caller uid XXXX is different than the authenticator's uid But i didnt get solution. What is uid? to which uid it comparing.

I am trying

    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 than authenticator's uid .

What it means? how do i correct it?

Any one please tell me how to solve this a complete code will be very helpful.

Community
  • 1
  • 1
Shivaraj Patil
  • 8,186
  • 4
  • 29
  • 56

1 Answers1

6

The UID is the user-id assigned to your application. Every application have it's own UID but if you create several applications yourself it is possible to make them share the same UID.

The authenticator is the module that handles and authenticates accounts that belongs to that authenticator. So Google's authenticator is used for handling Google's accounts and "authenticator X" is used to handle "X accounts".

AddAccountExplicitly is a method that is meant to be used when creating accounts of your own type with your own authenticator. The documentation for AddAccountExplicitly say:

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

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

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

Depending on what you want to do maybe you can show the "Add Account" dialog to the user and let the user add an account themself: Programatically starting the 'Add Account' activity in Android 2.2

Or maybe you could use the Admin SDK's directory API to create accounts that can be used with Google services but that isn't a Google account: Can I create a Google account programmatically?

Community
  • 1
  • 1
nibarius
  • 4,007
  • 2
  • 38
  • 56
  • nibarius Thanks for your explanation. In my app i just want to share one of my Google Drive file to user when user enter his email-id and press Register Button in Register Activity. What i thought is when he press register button in background add my google account details(unamem ,pwd) login and share the file and then remove my account credentials from users mobile and start Home Activity. Is there any other way to do the same? – Shivaraj Patil Mar 17 '14 at 11:26
  • 1
    Storing your account username and password in the app would generally be a really bad idea since anyone with access to the app could extract the information from the apk and take over your account. Unfortunately I don't have any ideas on how you can accomplish what you want with Google drive. – nibarius Mar 17 '14 at 12:43