Android Intent Action “ACTION_INSERT_OR_EDIT” - should it be used for adding contacts?

大城市里の小女人 提交于 2019-12-20 10:26:12

问题


At the moment I am searching for an easy and supported way of adding contacts in Android up from SDK level 7. (when some kind of data like the phone number is available) I looked at the default contact application and found "Intent.ACTION_INSERT_OR_EDIT" which is used for adding a new contact (or adding a number to a contact from the contact provider) from the dialer screen with the mime type "vnd.android.cursor.item/person". Now it would be nice to know how to find some documentation about the extras that should be added when using that action and if it is the correct way trying to support as much as possible handsets.

I'm looking forward reading your ideas. Thank you very much.

Regards.


回答1:


As much of the Android documentation goes, the documentation for native intents is pretty slim, but the available extras are listed here: http://developer.android.com/reference/android/provider/ContactsContract.Intents.Insert.html

Here is an example:

Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, "example@example.com");
startActivity(intent);

The code above should start an activity that lets you pick a contact to edit with the "example@example.com" inserted as a new email, or let you create a new contact with "example@example.com" inserted as the email.



来源:https://stackoverflow.com/questions/3520499/android-intent-action-action-insert-or-edit-should-it-be-used-for-adding-con

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