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

Android 如何使从应用程序导出到电话簿的新联系人可编辑,android,android-contacts,android-syncadapter,Android,Android Contacts,Android Syncadapter,我有一个应用程序,它有自己的联系人集,这些联系人来自服务器。我正在将此联系人导出到本机联系人数据库。这样我就可以从电话簿上访问它了。但是,我想使这些联系人在本机应用程序中可编辑 我正在为此使用帐户验证器和syncadapter方法 下面是我的同步适配器xml <sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" android:contentAuthority="com.android.co

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

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

下面是我的
同步适配器
xml

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

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

您需要做的几件事:

  • 实现一个
    SyncService
    并在
    AndroidManifest
  • 创建一个
    contacts.xml
    文件,该文件将告诉联系人编辑器如何解析和编辑与您的帐户相关的联系人
  • 见:


    例如。

    Thankyou@marmor。我正在同步的服务器不支持每个联系人发送超过3封电子邮件。此外,它也有一定的限制,如手机的工作类型最大允许为2。我们可以在contacts.xml中设置这些规则吗?还有,我需要使用哪些关键字?任何链接/教程都将不胜感激。我尝试了下面这样的方法,但联系人编辑器没有遵守限制。下载“谷歌联系人”并检查他们的编辑器是否工作正常,如果工作正常,这是你的股票联系人应用程序中的一个错误,如果没有,可能是你没有正确声明的内容,试着在以下位置安装并使用代码:看看这是否适合您我认为您是对的,它在Google联系人中运行良好。但在我的三星原生应用程序中。不太好用,谢谢你!我感谢你的帮助!还有一个问题。我找不到EditSchema的任何相关文档。我们如何限制特定类型的出现。e、 g-手机型手机最多允许2个。我可以做类似的事情吗?
    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);
                }
            }
        }
    }