从设置中隐藏同步适配器的虚拟帐户 [英] Hide dummy Account for Sync Adapter from Settings
问题描述
我创建了一个带有虚拟帐户的同步适配器,我不希望它出现在设置"应用程序的帐户"列表中,也不希望它出现在用户按下设置"中的添加帐户"按钮时.我在我的同步适配器定义中尝试了 android:userVisible="false",但仍然出现帐户.我已经在模拟器和 3 个物理设备上尝试过这个.一切正常,因为它同步了我需要的所有数据,唯一的错误是我在列表中看到了帐户,但我不想这样做.
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.
我的 authenticationator.xml 是:
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"
/>
我的syncadapter.xml 是:
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.
请帮忙!:)
推荐答案
我找到了解决方案.这是authenticator.xml 的样子:
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"
/>
你不能有这些行:
android:icon="@drawable/ic_launcher"
android:smallIcon="@drawable/ic_launcher"
android:label="@string/app_name"
如果您放置它们,无论您是否设置 android:userVisible="false",该帐户都将可见.
If you put them, the account will be visible wherever you set android:userVisible="false" or not.
这篇关于从设置中隐藏同步适配器的虚拟帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!