小编Ast*_*gor的帖子

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

我创建了一个带有虚拟帐户的同步适配器,我不希望它出现在"设置"应用程序的"帐户"列表中,也不希望用户按下"设置"中的"添加帐户"按钮.我在同步适配器定义中尝试了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)

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

请帮忙!:)

account android android-syncadapter

24
推荐指数
2
解决办法
5946
查看次数

标签 统计

account ×1

android ×1

android-syncadapter ×1