24

I have created a Sync Adapter with a dummy Account and I don't want it to appear on the Account list in the Settings application, nor when a user presses the add account button in Settings. I have tried android:userVisible="false" in my sync-adapter definition, but still the account appears. I've tried this on an emulator and 3 physical devices. Everything works correctly in terms that it syncs all the data I need, the only thing wrong is that I see the Account on the list, and I don't want to.

My authenticator.xml is:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
                   android:accountType="net.astagor.android.hhp.account"
                   android:icon="@drawable/ic_launcher"
                   android:smallIcon="@drawable/ic_launcher"
                   android:label="@string/app_name"
    />

My syncadapter.xml is:

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
          android:contentAuthority="net.astagor.android.hhp"
          android:accountType="net.astagor.android.hhp.account"
          android:userVisible="false"
          android:supportsUploading="true"
          android:allowParallelSyncs="false"
          android:isAlwaysSyncable="true"
    />

And I add my adpater like this:

 Account account = AuthenticatorService.GetAccount();

 AccountManager accountManager = (AccountManager) context
    .getSystemService(Context.ACCOUNT_SERVICE);

 if (accountManager.addAccountExplicitly(account, null, null)) {

ContentResolver.setIsSyncable(account, StubProvider.AUTHORITY, 1);

ContentResolver.setSyncAutomatically(account,
        StubProvider.AUTHORITY, true);

ContentResolver.addPeriodicSync(account, StubProvider.AUTHORITY,
        new Bundle(), SYNC_FREQUENCY);
 }

And the I get the account on the account list and in the add account list.

Help please! :)

Astagor
  • 299
  • 2
  • 8
  • I am very interested to the answer of this question(if there is a better way) – Johnny Z Jan 23 '14 at 21:36
  • Same problem here. Took everything from the docs just like you - don't want a dummyaccount to be visible, but it simply always shows! :-( What is broken here? – Zordid Jul 21 '15 at 07:42

2 Answers2

5

I found the solution. This is how authenticator.xml should look like:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
                   android:accountType="net.astagor.android.hhp.account"

    />

You must not have these lines:

               android:icon="@drawable/ic_launcher"
               android:smallIcon="@drawable/ic_launcher"
               android:label="@string/app_name"

If you put them, the account will be visible wherever you set android:userVisible="false" or not.

Astagor
  • 299
  • 2
  • 8
  • 5
    You still get a blank row though in the available accounts list, If you go to Settings > Add Account , There's now a blank row at the top for me. You also get warnings printed in the log by the settings app, with your package name. not ideal either : 2671-2671/? W/ChooseAccountActivity﹕ No label resource for account type my.package.name.account 2671-2671/? W/ChooseAccountActivity﹕ No icon resource for account type my.package.name.account 2671-2671/? W/AuthenticatorHelper﹕ No label icon for account type my.package.name.account – Jason Jan 09 '14 at 17:09
  • True, there is an empty position in the Add Account list. So how are people using dummy accounts, or they are not using sync adapters at all? – Astagor Jan 13 '14 at 07:04
3

This isn't a real answer, but if you remove the label from the authenticator.xml , it does not show in the list of added accounts , but the icon is there with no label in the list after clicking add account. Ugly and probably not a good idea. (this method does hide account at least on my nexus 4 running 4.4 - haven't checked other devices yet).

I believe the user visible flag in sync adapter only affects the display of the sync part after selecting an account, where you can see the last sync time, set auto sync settings, and trigger sync.

I'd love to know this also. It must be possible, as I don't see my accounts list littered with dummy accounts. So either there's a way or almost none of my installed apps are bothering with sync adapters?

Jason
  • 757
  • 4
  • 10