3

The registration for C2DM may result in an error ACCOUNT_MISSING. This error must be handled, according to the documentation, in this way "The application should ask the user to open the account manager and add a Google account."

I would like to offer to the user this possibility from the application. I have seen two ways to show this screen:

//Intent
context.startActivity(newIntent(Settings.ACTION_ADD_ACCOUNT).putExtra(Settings.EXTRA_AUTHORITIES, new String[] {?}));

The problem for this solution that the I have tried several EXTRA_AUTHORITIES ("com.google", "com.google.android.gsf, etc) and none of them show anything and if the parameter EXTRA_AUTHORITIES is omitted all the phone account are shown.

//Account manager    
AccountManager.get(context).addAccount("com.google", null, null, null, this, new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> accountManagerHandle) {
            //TODO Handle response.
        }
    }, null);
}

The problem for this solution is that it requires the permission MANAGE_ACCOUNTS, and the users would probably not like to accept an extra permission just for that.

How would you deal with this situation?

  • 1
    I am going to use the AccountManager based approach. Apparently nobody has not found the EXTRA_AUTHORITIES value for a Google account. Too bad that Google does not provide any hint to make the error handling of their push more user friendly. – Diego Gómez Olvera Jul 08 '11 at 10:11

1 Answers1

1

For the EXTRA_AUTHORITIES field you can use "gmail-ls" to show only the Google account selector.

After much googling I found the constant in the android.provider.Gmail source code:

public static final String AUTHORITY = "gmail-ls"

This class is not part of the public API so as a workaround it's a bit fragile :-(.

tonys
  • 3,855
  • 33
  • 39