【问题标题】:Use Android Contacts app to edit a raw contact which was added by a custom ContentProvider使用 Android 联系人应用程序编辑由自定义 ContentProvider 添加的原始联系人
【发布时间】:2014-03-19 15:36:57
【问题描述】:

我的应用使用自定义 ContentProvider 将联系人“Bob”添加到通讯录。 在 Android 通讯录应用中,Bob 与任何其他 (Google) 联系人一样显示。但是当我在联系人应用程序中编辑 Bob 时,我的应用程序提供的数据是不可编辑的。到目前为止一切顺利。

我的问题是:在我的应用程序中,有没有办法启动通讯录应用程序,允许用户编辑 Bob 的部分属于我的应用?

我尝试使用相应的Intent,如Android guide 中所述,但使用 Bobraw 联系人 uri:

Uri rawUri = getRawContactUri("Bob");
Intent intent = new Intent(Intent.ACTION_EDIT, rawUri);
startActivityForResult(intent, EDIT_CONTACT_RESULT);

这会打开通讯录应用程序,但仍然无法编辑 Bob 的数据。

有很多关于 SO 的问题涉及如何open your app from within the Contacts app when a custom field is selectedhow to fire ACTION_EDIT correctly
但我没有找到任何声明 - 包括参考 - 如果可以使用联系人应用程序让用户编辑自定义原始联系人。有没有人有线索,最好是参考?

【问题讨论】:

    标签: android android-intent android-contentprovider android-contacts


    【解决方案1】:

    您需要将 EditSchema 添加到您的 contact.xml 文件并添加元数据,指向清单文件的 SyncService 部分中的该文件,如下所示:

    <service
        android:name=".syncadapter.SyncService"
        android:exported="true">
    
        <intent-filter>
            <action android:name="android.content.SyncAdapter" />
        </intent-filter>
    
        <meta-data
            android:name="android.content.SyncAdapter"
            android:resource="@xml/syncadapter" />
        <meta-data
            android:name="android.provider.CONTACTS_STRUCTURE"
            android:resource="@xml/contacts" />
    </service>
    

    以下是官方来源中的 EditSchema 示例:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.2.2_r1/packages/apps/Contacts/tests/res/xml/test_basic_contacts.xml/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多