使用Android联系人应用程序来编辑由自定义ContentProvider添加的原始联系人 [英] Use Android Contacts app to edit a raw contact which was added by a custom ContentProvider
问题描述
我的应用程序使用自定义的ContentProvider
将联系人"鲍勃"添加到通讯录中.
在Android联系人应用中, Bob 会像其他任何(Google)联系人一样显示.但是,当我在联系人"应用程序中编辑 Bob 时,我的应用程序提供的数据不可编辑.到目前为止一切顺利.
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.
我的问题是:在我的应用程序中,是否有一种方法可以启动联系人"应用程序,从而允许用户编辑 Bob 的部分属于我的应用?
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);
会启动联系人"应用程序,但仍无法编辑 Bob 的数据.
which brings up the Contacts app, but still without the possibility to edit Bob's data.
关于SO的问题很多,涉及如何打开您的应用从联系人"应用中选择一个自定义字段后或如何触发ACTION_EDIT
正确.
但是,如果可以使用联系人"应用程序让用户编辑自定义的原始联系人,我没有找到任何陈述(包括参考).有没有人有线索,最好是参考?
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?
推荐答案
您需要将EditSchema添加到contact.xml文件并添加元数据,指向清单文件的SyncService部分中的该文件,如下所示:
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/
这篇关于使用Android联系人应用程序来编辑由自定义ContentProvider添加的原始联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!