I am working to get all the contacts from phone book and SIM card in my application. I want to store those all contacts in my application SQLite DB. The code with which I am wor
The following code will return all the names of the contact and you can set in text view-
Cursor cursor = null;
String name, phoneNumber,image,email;
try {
cursor = getApplicationContext().getContentResolver()
.query(Phone.CONTENT_URI, null, null, null, null);
int nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);
int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
int photoIdIdx = cursor.getColumnIndex(Phone.PHOTO_URI);
cursor.moveToFirst();
do {
HashMap hashMap = new HashMap();
name = cursor.getString(nameIdx);
phoneNumber = cursor.getString(phoneNumberIdx);
image = cursor.getString(photoIdIdx);
//email=cursor.getString(emailIdx);
if(!phoneNumber.contains("*"))
{
hashMap.put("name", "" + name);
hashMap.put("phoneNumber", "" + phoneNumber);
hashMap.put("image", "" + image);
//hashMap.put(email, ""+email);
hashMapsArrayList.add(hashMap);
}
} while (cursor.moveToNext());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
myAdapter=new MyAdapter();
listView.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}