0

是否可以为多个帐户类型拥有同步适配器? (如com.google和com.facebook.auth.login)适用于多个帐户类型的同步适配器

看来syncadapter.xml只接受像一个单一的值:

<?xml version="1.0" encoding="utf-8"?> 
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" 
    android:contentAuthority="com.foo" 
    android:accountType="com.google" 
    android:supportsUploading="true" 
    android:userVisible="true" /> 

我希望有适合我的用户喜欢几个帐户选项谷歌,脸谱和推特。

+0

我没有明白。为什么你尝试使用几种账户类型?帐户类型与服务器地址无关。你能解释一下吗? – azad

回答

0

虽然AbstractThreadedSyncAdapter的文档使用复数(强调),见

了Android:contentAuthority和android:ACCOUNTTYPE属性指出哪些内容管理局和占类型此同步适配器提供。

我不认为它支持。我不完全确定,但它看起来像this is the code for how the sync-adapter xml is parsed。我预计一些循环到ACCOUNTTYPE属性分成多种类型,如果它有这种支持:

79  static class MySerializer implements XmlSerializerAndParser<SyncAdapterType> { 
80   public void writeAsXml(SyncAdapterType item, XmlSerializer out) throws IOException { 
81    out.attribute(null, "authority", item.authority); 
82    out.attribute(null, "accountType", item.accountType); 
83   } 
84 
85   public SyncAdapterType createFromXml(XmlPullParser parser) 
86     throws IOException, XmlPullParserException { 
87    final String authority = parser.getAttributeValue(null, "authority"); 
88    final String accountType = parser.getAttributeValue(null, "accountType"); 
89    return SyncAdapterType.newKey(authority, accountType); 
90   } 

然而,也许是可以添加一个XML支持你,但指的是同一内容的权威每个账户类型?

+0

,因为元数据标签包含在AndroidManifest.xml的service-tag中,所以需要多个服务。 –

+0

确实。查看initializeSyncAdapter的代码我怀疑Android是为处理这种情况而设计的。它似乎假定SyncAdapter与特定的帐户类型具有一对一的关系。也许您最好的选择是创建自定义帐户类型并使用OAuth让用户在OAuth服务提供商处重复使用他们的帐户。 – andyandy

相关问题