从设置中隐藏同步适配器的虚拟帐户

Ast*_*gor 24 account android android-syncadapter

我创建了一个带有虚拟帐户的同步适配器,我不希望它出现在"设置"应用程序的"帐户"列表中,也不希望用户按下"设置"中的"添加帐户"按钮.我在同步适配器定义中尝试了android:userVisible ="false",但仍然显示该帐户.我在仿真器和3个物理设备上试过这个.一切都正常工作,它同步我需要的所有数据,唯一的错误是我在列表上看到帐户,我不想.

我的authenticator.xml是:

<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"
    />
Run Code Online (Sandbox Code Playgroud)

我的syncadapter.xml是:

<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"
    />
Run Code Online (Sandbox Code Playgroud)

我添加我的adpater像这样:

 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);
 }
Run Code Online (Sandbox Code Playgroud)

我在帐户列表和添加帐户列表中获取帐户.

请帮忙!:)

Ast*_*gor 5

我找到了解决方案。这是authenticator.xml 的样子:

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

    />
Run Code Online (Sandbox Code Playgroud)

你不能有这些行:

               android:icon="@drawable/ic_launcher"
               android:smallIcon="@drawable/ic_launcher"
               android:label="@string/app_name"
Run Code Online (Sandbox Code Playgroud)

如果您放置它们,无论您是否设置 android:userVisible="false" ,该帐户都将可见。

  • 尽管在可用帐户列表中,您仍然会看到一个空白行,如果您转到 Settings &gt; Add Account ,现在顶部有一个空白行供我使用。您还会收到设置应用程序在日志中打印的警告,以及您的包名称。也不理想:2671-2671/? W/ChooseAccountActivity:没有账户类型的标签资源 my.package.name.account 2671-2671/? W/ChooseAccountActivity:没有帐户类型 my.package.name.account 2671-2671/? W/AuthenticatorHelper:帐户类型 my.package.name.account 没有标签图标 (5认同)

Jas*_*son 3

这不是真正的答案,但如果您从authenticator.xml中删除标签,它不会显示在已添加帐户的列表中,但单击“添加帐户”后列表中没有标签,图标仍然存在。丑陋而且可能不是一个好主意。(此方法至少在运行 4.4 的 Nexus 4 上隐藏帐户 - 尚未检查其他设备)。

我相信同步适配器中的用户可见标志仅影响选择帐户后同步部分的显示,您可以在其中查看上次同步时间、设置自动同步设置和触发同步。

我也很想知道这个。这一定是可能的,因为我没有看到我的帐户列表中散布着虚拟帐户。那么要么有办法,要么我安装的应用程序几乎没有一个会打扰同步适配器?