添加联系人时显示自定义同步适配器作为选项

Posted

技术标签:

【中文标题】添加联系人时显示自定义同步适配器作为选项【英文标题】:Display custom sync adapter as an option when adding contacts 【发布时间】:2013-10-12 07:11:26 【问题描述】:

我正在按照 SDK 示例中的示例编写自定义同步适配器,一切似乎都运行良好。我可以从我的服务器同步回联系人并将它们显示在联系人应用程序中。

但是,我无法将联系人直接添加到我的服务器。具体来说,除了 Google 和 Corporate 之外,我希望我的同步适配器在添加联系人屏幕上的 Spinner 中作为一个选项出现,如屏幕截图所示。我在互联网上找不到任何关于此的内容。

【问题讨论】:

【参考方案1】:

好的,我想通了。结果发现,定义 SDK 示例附带的 ContactsAccountType 的 contacts.xml 文件非常简单。稍微充实一下,我的同步适配器就会出现在 Spinner (beginning with android 4.0.3 according to this bug report) 中。

here 提供了显示所有可用字段的示例。我把它复制在下面以供参考:

<ContactsAccountType
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditSchema
    >
    <!--
        Name:
        - maxOccurs must be 1
        - No types.

        - Currently all the supportsXxx attributes must be true, but here's the plan for the
          future:
          (There's some hardcoded assumptions in the contact editor, which is one reason
          for the above restriction)

            - "Family name" and "Given name" must be supported.
                - All sync adapters must support structured name. "display name only" is not
                  supported.
                  -> Supporting this would require relatively large changes to
                     the contact editor.

            - Fields are decided from the attributes:
                StructuredName.DISPLAY_NAME         if supportsDisplayName == true
                StructuredName.PREFIX               if supportsPrefix == true
                StructuredName.FAMILY_NAME          (always)
                StructuredName.MIDDLE_NAME          if supportsPrefix == true
                StructuredName.GIVEN_NAME           (always)
                StructuredName.SUFFIX               if supportsSuffix == true
                StructuredName.PHONETIC_FAMILY_NAME if supportsPhoneticFamilyName == true
                StructuredName.PHONETIC_MIDDLE_NAME if supportsPhoneticMiddleName == true
                StructuredName.PHONETIC_GIVEN_NAME  if supportsPhoneticGivenName == true

            - DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME  is always added.
            - DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME is added
              if any of supportsPhoneticXxx == true
    -->
    <!-- Fallback/Google definition.  Supports all. -->
    <DataKind kind="name"
        maxOccurs="1"
        supportsDisplayName="true"
        supportsPrefix="true"
        supportsMiddleName="true"
        supportsSuffix="true"
        supportsPhoneticFamilyName="true"
        supportsPhoneticMiddleName="true"
        supportsPhoneticGivenName="true"
        >
    </DataKind>

    <!-- Exchange definition.  No display-name, no phonetic-middle.
    <DataKind kind="name"
        supportsDisplayName="false"
        supportsPrefix="true"
        supportsMiddleName="true"
        supportsSuffix="true"
        supportsPhoneticFamilyName="true"
        supportsPhoneticMiddleName="false"
        supportsPhoneticGivenName ="true"
        >
    </DataKind>
    -->

    <!--
        Photo:
        - maxOccurs must be 1
        - No types.
    -->
    <DataKind kind="photo" maxOccurs="1" />

    <!--
        Phone definition.
        - "is secondary?" is inferred from type.
    -->
    <!-- Fallback, Google definition.  -->
    <DataKind kind="phone" >
        <!-- Note: Google type doesn't have obsolete ones -->
        <Type type="mobile" />
        <Type type="home" />
        <Type type="work" />
        <Type type="fax_work" />
        <Type type="fax_home" />
        <Type type="pager" />
        <Type type="other" />
        <Type type="custom"/>
        <Type type="callback" />
        <Type type="car" />
        <Type type="company_main" />
        <Type type="isdn" />
        <Type type="main" />
        <Type type="other_fax" />
        <Type type="radio" />
        <Type type="telex" />
        <Type type="tty_tdd" />
        <Type type="work_mobile"/>
        <Type type="work_pager" />
        <Type type="assistant" />
        <Type type="mms" />
    </DataKind>

    <!-- Exchange definition.
    <DataKind kind="phone" >
        <Type type="home" maxOccurs="2" />
        <Type type="mobile" maxOccurs="1" />
        <Type type="work" maxOccurs="2" />
        <Type type="fax_work" maxOccurs="1" />
        <Type type="fax_home" maxOccurs="1" />
        <Type type="pager" maxOccurs="1" />
        <Type type="car" maxOccurs="1" />
        <Type type="company_main" maxOccurs="1" />
        <Type type="mms" maxOccurs="1" />
        <Type type="radio" maxOccurs="1" />
        <Type type="assistant" maxOccurs="1" />
    </DataKind>
    -->

    <!--
        Email
    -->
    <!-- Fallback/Google definition.  -->
    <DataKind kind="email" >
        <!-- Note: Google type doesn't have obsolete ones -->
        <Type type="home" />
        <Type type="work" />
        <Type type="other" />
        <Type type="mobile" />
        <Type type="custom" />
    </DataKind>

    <!--
        Exchange definition.
        - Same definition as "fallback" except for maxOccurs=3
    <DataKind kind="email" maxOccurs="3" >
        <Type type="home" />
        <Type type="work" />
        <Type type="other" />
        <Type type="mobile" />
        <Type type="custom" />
    </DataKind>
    -->

    <!--
        Nickname
        - maxOccurs must be 1
        - No types.
    -->
    <DataKind kind="nickname" maxOccurs="1" />

    <!--
        Im:
         - The TYPE column always stores Im.TYPE_OTHER (defaultValues is always set)
         - The user-selected type is stored in Im.PROTOCOL
    -->
    <!-- Fallback, Google definition.  -->
    <DataKind kind="im" >
        <Type type="aim" />
        <Type type="msn" />
        <Type type="yahoo" />
        <Type type="skype" />
        <Type type="qq" />
        <Type type="google_talk" />
        <Type type="icq" />
        <Type type="jabber" />
        <Type type="custom" />
    </DataKind>

    <!-- Exchange definition.
    <DataKind kind="im" maxOccurs="3" >
        <Type type="aim" />
        <Type type="msn" />
        <Type type="yahoo" />
        <Type type="skype" />
        <Type type="qq" />
        <Type type="google_talk" />
        <Type type="icq" />
        <Type type="jabber" />
        <Type type="custom" />
    </DataKind>
    -->

    <!--
        Postal address.
    -->
    <!-- Fallback/Google definition.  Not structured. -->
    <DataKind kind="postal" needsStructured="false" >
        <Type type="home" />
        <Type type="work" />
        <Type type="other" />
        <Type type="custom" />
    </DataKind>

    <!-- Exchange definition.  Structured.
    <DataKind kind="postal" needsStructured="true" >
        <Type type="work" />
        <Type type="home" />
        <Type type="other" />
    </DataKind>
    -->

    <!--
        Organization:
        - Fields are fixed: COMPANY, TITLE
        - maxOccurs must be 1
        - No types.
    -->
    <DataKind kind="organization" maxOccurs="1" />

    <!--
        Website:
        - No types.
    -->
    <DataKind kind="website" />

    <!--
        Below kinds have nothing configurable.
        - No types are supported.
        - maxOccurs must be 1
    -->
    <DataKind kind="sip_address" maxOccurs="1" />
    <DataKind kind="note" maxOccurs="1" />

    <!--
        Google/Exchange supports it, but fallback doesn't.
    <DataKind kind="group_membership" maxOccurs="1" />
    -->

    <!--
        Event
    -->
    <DataKind kind="event" dateWithTime="false">
        <Type type="birthday" maxOccurs="1" yearOptional="true" />
        <Type type="anniversary" />
        <Type type="other" />
        <Type type="custom" />
    </DataKind>

    <!--
        Exchange definition.  dateWithTime is needed only for Exchange.
    <DataKind kind="event" dateWithTime="true">
        <Type type="birthday" maxOccurs="1" />
    </DataKind>
    -->

    <!--
        Relationship
    -->
    <DataKind kind="relationship" >
        <Type type="assistant" />
        <Type type="brother" />
        <Type type="child" />
        <Type type="domestic_partner" />
        <Type type="father" />
        <Type type="friend" />
        <Type type="manager" />
        <Type type="mother" />
        <Type type="parent" />
        <Type type="partner" />
        <Type type="referred_by" />
        <Type type="relative" />
        <Type type="sister" />
        <Type type="spouse" />
        <Type type="custom" />
    </DataKind>
</EditSchema>

【讨论】:

以上是关于添加联系人时显示自定义同步适配器作为选项的主要内容,如果未能解决你的问题,请参考以下文章

违反约束时显示自定义消息 PL/SQL

打开约会项目时显示自定义任务窗格(会议发生和个人会议)

下载文件时显示自定义对话框

仅在填充Wordpress时显示自定义字段

Angular:ngFor数据项并在为空时显示自定义消息

UILabel 在使用文本设置属性时显示自定义字体错误,但在代码中设置时工作正常