【发布时间】:2011-09-01 11:26:36
【问题描述】:
我正在制作一个应用程序来在服务器端上传安卓设备的电话簿。 我可以得到电话簿中的姓名,但我没有得到各自姓名的联系电话。
我正在使用People.NUMBER 方法获取联系人号码。
【问题讨论】:
我正在制作一个应用程序来在服务器端上传安卓设备的电话簿。 我可以得到电话簿中的姓名,但我没有得到各自姓名的联系电话。
我正在使用People.NUMBER 方法获取联系人号码。
【问题讨论】:
检查这些链接:
How to call Android contacts list?
How to get contacts from native phonebook in android
How to obtain all details of a contact in Android
How to get the first name and last name from Android contacts?
How to import contacts from phonebook to our application
How to get all android contacts but without those which are on SIM
【讨论】:
使用此代码。此代码将 Contant 名称和编号存储在 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){}
}
根据需要使用 contactData 列表。
【讨论】: