检索电话簿在Android上的联系方式 [英] Retrieving the contact details of phonebook in android
本文介绍了检索电话簿在Android上的联系方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提出一个应用程序上传Android设备的电话簿上的服务器端。 我能得到在电话簿中的名字,但我没有得到相应名称的联系号码。
I am making an app to upload the phonebook of an android device on server side. I am able to get the names in the phonebook but I am not getting the contact numbers of respective names.
我使用 People.NUMBER
方法获取不接触的。
I am using People.NUMBER
method for getting the no of a contact.
推荐答案
使用code。这code存储Contant姓名和电话号码,在Arralist。
use this code. this code stores the Contant name and number in the Arralist.
ArrayList<HashMap<String,String>> contactData=new ArrayList<HashMap<String,String>>();
ContentResolver cr = getContentResolver();
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
while (cursor.moveToNext()) {
try{
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
while (phones.moveToNext()) {
String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
HashMap<String,String> map=new HashMap<String,String>();
map.put("name", name);
map.put("number", phoneNumber);
contactData.add(map);
}
phones.close();
}
}catch(Exception e){}
}
使用联络人资料列表中,你所需要的。
Use the contactData list as you need.
这篇关于检索电话簿在Android上的联系方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文