如何通过 LookUpKey 获取联系电话号码?
Posted
技术标签:
【中文标题】如何通过 LookUpKey 获取联系电话号码?【英文标题】:How can i get the contact phone number by LookUpKey? 【发布时间】:2015-06-19 21:10:41 【问题描述】:我已经在 androidManifest 文件中注册了一个意图,以使我的应用在用户在联系人应用中选择联系人时弹出,并且我成功检索了查找键,但我找不到获取联系选择的详细信息,我已经使用光标查看了其他一些信息,但是当我执行查询功能时,我的应用程序崩溃了,这是我检索查找键的代码
Intent intent = getIntent();
String action = intent.getAction();
Uri contactUri = intent.getData();
if (Intent.ACTION_VIEW.equals(action))
// here i don't know what to use to search for the contact by the contactUri
所以,我必须得到联系人姓名和联系电话!
【问题讨论】:
***.com/questions/14069375/… 【参考方案1】:Intent intent = getIntent();
String action = intent.getAction();
Uri contactUri = intent.getData();
if (Intent.ACTION_VIEW.equals(action))
Log.d("START","Getting all Contacts");
ArrayList<PhoneContactInfo> arrContacts = new ArrayList<PhoneContactInfo>();
PhoneContactInfo phoneContactInfo=null;
Cursor cursor = context.getContentResolver().query(contactUri , new String[] ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone._ID, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
cursor.moveToFirst();
while (cursor.isAfterLast() == false)
String contactNumber= cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
int phoneContactID = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));
phoneContactInfo = new PhoneContactInfo();
phoneContactInfo.setPhoneContactID(phoneContactID);
phoneContactInfo.setContactName(contactName);
phoneContactInfo.setContactNumber(contactNumber);
if (phoneContactInfo != null)
arrContacts.add(phoneContactInfo);
phoneContactInfo = null;
cursor.moveToNext();
cursor.close();
cursor = null;
Log.d("END","Got all Contacts");
【讨论】:
以上是关于如何通过 LookUpKey 获取联系电话号码?的主要内容,如果未能解决你的问题,请参考以下文章