Tôi đang cố gắng lấy danh bạ từ nhật ký cuộc gọi. Tôi có thể lấy các số liên lạc từ danh bạ chính sử dụng mã này:Android - Cách nhận liên hệ từ nhật ký cuộc gọi?
public void getContacts(View view) {
Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intentContact, 0);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == 0)
{
try {
to.setText(getContactInfo(intent));
} catch(NullPointerException e) {
// Do nothing ;)
}
}
}
protected String getContactInfo(Intent intent)
{
String phoneNumber = to.getText().toString();
Cursor cursor = managedQuery(intent.getData(), null, null, null, null);
while (cursor.moveToNext())
{
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
if(phoneNumber.endsWith(">"))
phoneNumber += ", "+name;
else
phoneNumber += name;
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1"))
hasPhone = "true";
else
hasPhone = "false" ;
if (Boolean.parseBoolean(hasPhone))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
while (phones.moveToNext())
{ phoneNumber = phoneNumber + " <" + phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))+">";
}
phones.close();
}
}
cursor.close();
return phoneNumber;
}
Điều này không được khi chúng ta bấm vào một nút "Liên hệ" nó mở ra một danh sách tất cả các điểm tiếp xúc, người dùng có thể chọn bất kỳ liên hệ và đó chọn địa chỉ liên hệ sẽ được thêm vào trường "Tới". Tôi muốn làm điều tương tự, nhưng thay vì hiển thị tất cả các liên hệ tôi muốn hiển thị chỉ những người gần đây đã được sử dụng (nhật ký cuộc gọi) để lựa chọn.
Cũng sẽ rất tuyệt nếu bạn có thể biết cách thực hiện điều này với các nhóm.
thử sử dụng Trình tạo nội dung .... – subrussn90