2013-10-24 90 views
24

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

我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" 
    /> 

我加我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); 
} 

而我得到的帐户列表和添加帐户列表中的帐户。

请帮忙! :)

+0

我对这个问题的答案很感兴趣(如果有更好的方法) –

+0

同样的问题在这里。从文档中获取所有内容,就像你一样 - 不要让虚拟帐户可见,但它总是显示! :-(这里有什么坏的? – Zordid

回答

3

这不是一个真正的答案,但如果你从authenticator.xml移除标签,它不添加帐户列表显示,但该图标有一个不带标签列表中点击后新增帐户。丑陋,可能不是一个好主意。 (这个方法至少在我的nexus 4运行4.4时隐藏帐户 - 还没有检查过其他设备)。

相信在同步适配器用户可见的标志只影响同步部分的显示选择帐户,在这里你可以看到最后同步时间后,设置自动同步设置,并触发同步。

我很想也知道这一点。这一定是可能的,因为我没有看到我的账户名单上充斥着虚拟账户。因此,无论是有一种方式,或几乎没有我的安装的应用程序正在打扰同步适配器?

4

我找到了解决办法。 这是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" 

如果你把他们的帐户,无论你设置的android可见:userVisible =”假“或不。

+4

尽管在可用的帐户列表中,你仍然会得到一个空行,如果你去设置>添加帐户,现在顶部有一个空白行 您还会收到警告不适用于: 2671-2671 /?W/ChooseAccountActivity:无帐户类型的标签资源my.package.name.account 2671-2671 /?W/ChooseAccountActivity:没有帐户类型的图标资源my.package.name.account 2671-2671 /?W/AuthenticatorHelper:没有帐户类型的标签图标my.package.name.account – Jason

+0

确实,添加帐户列表中存在空白位置。那么人们如何使用虚拟账户,或者他们根本不使用同步适配器? – Astagor