CModel.java
public class CModel {
String firstname;
String lastname;
String contactno;
String Imagepath;
int ID;
String contactid;
public String getCheck() {
return Check;
}
String Check;
public String getContactid() {
return contactid;
}
public CModel(String fnm, String lastname, String userprofile, int ID, String contactno, String Check) {
this.firstname = fnm;
this.lastname = lastname;
this.Imagepath = userprofile;
this.ID = ID;
this.contactno = contactno;
this.Check = Check;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
public String getContactno() {
return contactno;
}
public String getImagepath() {
return Imagepath;
}
public int getID() {
return ID;
}
in your activity file call this method
private ArrayList<CModel> getcontact() {
ArrayList<CModel> contactlist = new ArrayList<CModel>;
try {
Bitmap my_btmp = null;
String profilepic;
String phone = null;
contactlist = new ArrayList<CModel>();
ContentResolver cr = getContentResolver();
String[] projection = new String[]{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME};
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, projection, null, null,
ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
while (cur.moveToNext()) {
String contactId = cur.getString(cur.getColumnIndex(ContactsContract.Data._ID));
String displayName = cur.getString(cur.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
Uri my_contact_Uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId));
InputStream photo_stream = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), my_contact_Uri);
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{contactId}, null);
while (pCur.moveToNext()) {
phone = pCur.getString(
pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
pCur.close();
if (photo_stream != null) {
BufferedInputStream buf = new BufferedInputStream(photo_stream);
my_btmp = BitmapFactory.decodeStream(buf);
profilepic = BitMapToString(my_btmp);
} else {
Bitmap bitmap = BitmapFactory.decodeResource(HomePage.this.getResources(), R.drawable.profilepic);
my_btmp = bitmap;
profilepic = BitMapToString(my_btmp);
}
String columns[] = {
ContactsContract.CommonDataKinds.Event.START_DATE,
ContactsContract.CommonDataKinds.Event.TYPE,
ContactsContract.CommonDataKinds.Event.MIMETYPE,
};
String where =ContactsContract.CommonDataKinds.Event.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE + "' and " + ContactsContract.Data.CONTACT_ID + " = " + contactId;
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME;
Cursor birthdayCur = cr.query(ContactsContract.Data.CONTENT_URI, columns, where, selectionArgs, sortOrder);
if (birthdayCur.getCount() > 0) {
if (birthdayCur.moveToFirst()) {
do {
contactlist.add(new CModel(displayName, "", profilepic, 0, phone,"phone"));
boolean flag = con.comparedata(phone);
} while (birthdayCur.moveToNext());
}
}
birthdayCur.close();
}
cur.close();
} catch (Exception e) {
}
return contactlist;
}