我正在尝试获取一组的所有详细信息(例如 - 家庭)。
编码:
Cursor c = managedQuery(Data.CONTENT_URI, new String[] {
Contacts.DISPLAY_NAME, Contacts._ID,GroupMembership.CONTACT_ID },
GroupMembership.GROUP_ROW_ID + " = ?",
new String[] { groupID }, Phone.TIMES_CONTACTED + " DESC");
获取姓名和照片:
while (c.moveToNext()&&temp_id<30)
{
String id = c.getString(personIdx);
//c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Log.e("myTag", id);
// get name
try{
personNameText = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}catch (Exception e) {
e.printStackTrace();
}
// get photo
try{
bmp = loadContactPhoto(getContentResolver(),Long.parseLong( id));
bmp = bmp.createScaledBitmap(bmp, getResources().getDrawable(R.drawable.contact).getIntrinsicWidth(),
getResources().getDrawable(R.drawable.contact).getIntrinsicHeight(), false);
}catch (Exception e) {
// TODO: handle exception
}
// get number and email
try
{
String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if ( hasPhone.equalsIgnoreCase("1"))
hasPhone = "true";
else
hasPhone = "false" ;
if (Boolean.parseBoolean(hasPhone))
{
getNumbers(id);
}
}catch (Exception e) {
e.printStackTrace();
}
// get email
String email = "";
try{
Cursor emailCur = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
new String[]{id}, null);
while (emailCur.moveToNext()) {
email = emailCur.getString(
emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}
emailCur.close();
}catch (Exception e) {
e.printStackTrace();
}
插入数据库
temp_id++;
insertData(temp_id, bitmaptoByteArray(bmp), phoneNamberText, personNameText,
email);
这里提到的所有功能都很好用!问题是我只得到人名而不是其他细节。我认为问题是我弄错了身份证。我将不胜感激!