Use Android Contacts app to edit a raw contact which was added by a custom ContentProvider

喜夏-厌秋 提交于 2020-01-01 16:59:17

问题


My app adds contact 'Bob' to the address book using a custom ContentProvider. In the Android Contacts app, Bob shows up just as any other (Google) contact. But when I edit Bob in the Contacts app, the data provided by my application is not editable. So far so good.

My question is: From within my app, is there a way to fire up the Contacts app, in a way that allows the user to edit the portion of Bob that belongs to my app?

I have tried to use the corresponding Intent, as described in this Android guide, but using the raw contact uri for Bob:

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

which brings up the Contacts app, but still without the possibility to edit Bob's data.

There are plenty of questions on SO covering how to open your app from within the Contacts app when a custom field is selected or how to fire ACTION_EDIT correctly.
But I did not find any statement - including a reference - if it is possible to use Contacts app to let the user edit custom raw contacts. Does anyone have a clue and preferably a reference?


回答1:


You need to add EditSchema to your contact.xml file and add meta-data, pointing to that file in SyncService section of your manifest file, like this:

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

Here is example of EditSchema in official sources: 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/



来源:https://stackoverflow.com/questions/21878237/use-android-contacts-app-to-edit-a-raw-contact-which-was-added-by-a-custom-conte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!