次のコードを試してください。
1)クリックオフボタンで次のことを試してください。
Intent in = new Intent(Intent.ACTION_INSERT);
in.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(in,ADD_DATA);
2)ONActivityResultメソッド:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ADD_DATA:
if(resultCode == RESULT_OK) {
Uri contactData = data.getData();
Cursor cur = managedQuery(contactData, null, null, null, null);
ContentResolver contect_resolver = getContentResolver();
if (cur.moveToFirst()) {
String id = cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
String lookupkey = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY));
String name = "";
String no = "";
Cursor phoneCur = contect_resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
if (phoneCur.moveToFirst()) {
name = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
no = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String lookup = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY));
System.out.println("Contact Name"+name);
System.out.println("Number"+no);
id = null;
name = null;
no = null;
phoneCur = null;
contect_resolver = null;
cur = null;
}
}
}
if(resultCode == RESULT_CANCELED)
{
}
break;
default:
break;
}
}