【发布时间】:2014-06-16 19:40:54
【问题描述】:
我正在创建一个联系人应用程序,但想在我的应用程序的原生 android 联系人应用程序中添加联系人,就像 Skype 或 WhatsApp 一样。我需要扩展什么类来实现这个功能?
这正是我想要创建的图片:
【问题讨论】:
我正在创建一个联系人应用程序,但想在我的应用程序的原生 android 联系人应用程序中添加联系人,就像 Skype 或 WhatsApp 一样。我需要扩展什么类来实现这个功能?
这正是我想要创建的图片:
【问题讨论】:
好的,如果我明白您在寻找什么。您想使用本机 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.
}
}
这是一个对光标的调用示例。请在 android 文档中阅读有关联系人光标的更多信息。
email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
【讨论】: