我正在製作應用程序以在服務器端上傳android設備的電話簿。 我能夠在電話簿中獲得姓名,但我沒有獲取各個姓名的聯繫電話號碼。在android中檢索電話簿的聯繫人詳細信息
我正在使用People.NUMBER
獲取聯繫方式的方法。
我正在製作應用程序以在服務器端上傳android設備的電話簿。 我能夠在電話簿中獲得姓名,但我沒有獲取各個姓名的聯繫電話號碼。在android中檢索電話簿的聯繫人詳細信息
我正在使用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
使用此代碼。這段代碼在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){}
}
,因爲你需要使用聯絡資料名單。