[英]How to add contact in Android like skype, whatsapp in native contact app?
I am creating a contact app but want to add contacts in the native android contact app from my app just like Skype or WhatsApp. 我正在创建联系人应用程序,但想从我的应用程序(如Skype或WhatsApp)中在本地android联系人应用程序中添加联系人。 What class would I need to extend to implement this functionality? 我需要扩展什么类来实现此功能?
Here is the picture of exactly what I want to create: 这正是我要创建的图片:
Ok if I understand what you are looking for. 好吧,如果我了解您的需求。 You want to use the native Android contact list.. If so then here are the steps: 您要使用本机Android联系人列表。如果是这样,请按照以下步骤操作:
A short example. 一个简短的例子。 fire intent 开火意图
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
//Receive the result
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case CONTACT_PICKER_RESULT:
//deal with the resulting contact info. I built a separate util class for that.. but here is an example of the code.
String[] projection = { ContactsContract.CommonDataKinds.Phone._ID, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Email.ADDRESS };
Uri result = data.getData();
String id = result.getLastPathSegment();
ContentResolver contentResolver = getActivity().getContentResolver();
//return cursor
cur = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
ContactsContract.CommonDataKinds.Phone._ID + " like \"" + idUser + "%\"", null, null);
//Use the cursor to return what you need.
}
}
Here is an example call to the cursor. 这是对游标的示例调用。 Please read some more about the contact cursor in the android docs. 请在android文档中阅读有关联系人游标的更多信息。
email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.