开发者

How to add custom data/field in contacts in android 2.0?

开发者 https://www.devze.com 2022-12-14 14:44 出处:网络
I\'m trying t开发者_JS百科o write an application where a user can enter his name, phone number, Facebook ID/ Twitter ID etc...which will then be added to the existing contacts application.

I'm trying t开发者_JS百科o write an application where a user can enter his name, phone number, Facebook ID/ Twitter ID etc...which will then be added to the existing contacts application.

Name, phone number - by default exists in the contacts app. How can I go about adding the Facebook ID or Twitter ID? I mean custom fields in the contacts application from my application.


You can easily do that by inserting you own mimetype:

Builder builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)
.withValue(ContactsContract.Data.MIMETYPE,"vnd.android.cursor.item/facebook")
.withValue("data1","bkhashfehFacebookId")

And then you can read your own data from your own application easily using (query) method and you pass you mimetype in the search criteria.

Also if you want to update an already existed contact, you just need to add new mimtype to that contact.


I have another suggestion also: you can add facebook information as IM address, by using the following code:

Builder builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)
.withValue(ContactsContract.Data.MIMETYPE,"ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE")
.withValue(ContactsContract.CommonDataKinds.Im.DATA,"bkhashfehFacebookId")
.withValue(ContactsContract.CommonDataKinds.Im.TYPE,ContactsContract.CommonDataKinds.Im.TYPE_WORK)
.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL,ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL)
.withValue(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL,"FaceBook")

in this case you can also see it in the Contacts application, not only in your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消