/**
* case 1 only nickname input
* @param nicknam
* @deprecated
*/
public void selectBynickname2(String nickname, TableLayout layout) {
//select contract nickname
String selectionNick = Nickname.NAME +" = ?";
String[] selectionArgsNick = new String[]{nickname};
ContentResolver cr = getContentResolver();
Cursor contractscursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, selectionNick, selectionArgsNick, null);
while(contractscursor.moveToNext()) {
int NICKNAME = contractscursor.getColumnIndex(Nickname.NAME);
int ID = contractscursor.getColumnIndex(ContactsContract.Contacts._ID);
int PHOTO = contractscursor.getColumnIndex(ContactsContract.Data.DATA15);
//int presence = (int)contractscursor.getLong(PRESENCE_STATUS);
String nicknametemp = (String)contractscursor.getString(NICKNAME);
String idtemp = (String)contractscursor.getString(ID);
byte[] phototemp = contractscursor.getBlob(PHOTO);
Bitmap photobmp = null;
if(Util.isEmpty(phototemp)) {
//default photo
photobmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
} else {
photobmp = BitmapFactory.decodeByteArray(phototemp, 0, phototemp.length);
}
//select email
String selectionEmail = Email.CONTACT_ID + " = ?";
String[] selectionArgsEmail = new String[]{idtemp};
Cursor emailcursor = cr.query(Email.CONTENT_URI,
null, selectionEmail, selectionArgsEmail, null);
while(emailcursor.moveToNext()) {
int EMAIL = emailcursor.getColumnIndex(Email.DATA);
String email = (String)emailcursor.getString(EMAIL);
layout.addView(row(new Contract(nickname, email,photobmp)));
}
}
}
/**
* case 1 only email input
* @param nicknam
* @deprecated
*/
public void selectByemail2(String email, TableLayout layout) {
ContentResolver cr = getContentResolver();
//select email
String selectionEmail = Email.DATA +" = ?";
String[] selectionArgsEmail = new String[]{email};
Cursor emailcursor = cr.query(Email.CONTENT_URI,
null, selectionEmail, selectionArgsEmail, null);
while(emailcursor.moveToNext()) {
int EMAIL = emailcursor.getColumnIndex(Email.DATA);
int ID = emailcursor.getColumnIndex(Email.CONTACT_ID);
String emailtemp = (String)emailcursor.getString(EMAIL);
String idtemp = (String)emailcursor.getString(ID);
//select contract nickname
String selectionNick = ContactsContract.Contacts._ID +" = ?";
String[] selectionArgsNick = new String[]{idtemp};
Cursor contractscursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, selectionNick, selectionArgsNick, null);
while(contractscursor.moveToNext()) {
int NICKNAME = contractscursor.getColumnIndex(Nickname.NAME);
int PHOTO = contractscursor.getColumnIndex(ContactsContract.Data.DATA15);
String nicknametemp = (String)contractscursor.getString(NICKNAME);
byte[] phototemp = contractscursor.getBlob(PHOTO);
Bitmap photobmp = null;
if(Util.isEmpty(phototemp)) {
photobmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
} else {
photobmp = BitmapFactory.decodeByteArray(phototemp, 0, phototemp.length);
}
layout.addView(row(new Contract(nicknametemp, emailtemp, photobmp)));
}
}
}
Android联系人数据库全
最新推荐文章于 2024-11-13 17:53:20 发布