我正在创建一个联系人应用程序,但想要从我的应用程序添加联系人在本机Android联系人应用程序,就像Skype或WhatsApp.我需要扩展哪个类来实现此功能?
这是我想要创建的图片:

小智 -3
好的,如果我明白你在寻找什么。您想要使用本机 Android 联系人列表。如果是这样,则步骤如下:
一个简短的例子。火意图
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.
}
}
Run Code Online (Sandbox Code Playgroud)
下面是一个对光标的调用示例。请阅读 android 文档中有关联系人光标的更多信息。
email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1646 次 |
| 最近记录: |