如何使从应用程序导出的新联系人以可编辑的形式导出到电话簿

How to make new contacts exported from an app to Phonebook as EDITABLE

我有一个应用程序,它有自己的一组来自服务器的联系人。我正在将此联系人导出到本机联系人数据库。这样我就可以从电话簿中访问它。但是,我想让这些联系人在本机应用程序中可编辑。

我正在为此使用帐户验证器和 syncadapter 方法。

下面是我的sync-adapterxml

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="com.android.contacts"
    android:supportsUploading="true"
    android:userVisible="true"
    android:accountType="com.example.myapp"
/>

设置android:supportsUploading="true"

此外,通过将以下标志设置为 0,将原始联系人和数据字段导出为非只读 android.provider.ContactsContract.RawContacts.RAW_CONTACT_IS_READ_ONLY android.provider.ContactsContract.RawContacts.DATA_IS_READ_ONLY

我仍然没有看到在本机应用程序中编辑我的联系人的选项。 这里缺少什么?

提前致谢

[更新] 我正在使用下面的代码来检查联系人支持哪种帐户类型并且是可编辑的。

final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
for (SyncAdapterType sync : syncs) {
    Log.d(TAG, "found SyncAdapter: " + sync.accountType);
    if (ContactsContract.AUTHORITY.equals(sync.authority)) {
        Log.d(TAG, "found SyncAdapter that supports contacts: " + sync.accountType);
        if (sync.supportsUploading()) {
            Log.d(TAG, "found SyncAdapter that supports contacts and is not read-only: " + sync.accountType);
            // we'll now get a list of all accounts under that accountType:
            Account[] accounts = AccountManager.get(this).getAccountsByType(sync.accountType);
            for (Account account : accounts) {
               Log.d(TAG, account.type + " / " + account.name);
            }
        }
    }
}

我的应用程序帐户类型是非只读的,但仍然看不到编辑选项。请帮忙

您需要做几件事:

  1. 实施 SyncService 并在 AndroidManifest
  2. 上声明
  3. 创建一个 contacts.xml 文件,联系人编辑器将如何解析和编辑与您的帐户相关的联系人

见: https://github.com/xwiki-contrib/android-authenticator/blob/master/app/src/main/AndroidManifest.xml#L81-L94 https://github.com/xwiki-contrib/android-authenticator/blob/master/app/src/main/res/xml/syncadapter.xml https://github.com/xwiki-contrib/android-authenticator/blob/master/app/src/main/res/xml/contacts.xml

作为示例。