I need to get contact's birthdays, but my code doesn't work
CODE.java----------------
Log.i(TAG, "Start reading birthdays from contacts");
Uri uri = ContactsContract.Data.CONTENT_URI;
Log.d(TAG, "1");
String[] projection = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Event.CONTACT_ID,
ContactsContract.CommonDataKinds.Event.START_DATE
};
Log.d(TAG, "2");
String where = ContactsContract.Data.MIMETYPE + "= ? AND " +
ContactsContract.CommonDataKinds.Event.TYPE + "=" +
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY;
Log.d(TAG, "3");
String[] selectionArgs = new String[] {ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE};
Log.d(TAG, "4");
Cursor cursor = managedQuery(uri, projection, where, selectionArgs, null);
while (cursor.moveToNext()) {
Log.d(TAG, "5");
String displayBirthday = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if(!displayBirthday.equals("")){
Log.d(TAG, "6");
tvCon.setText(name + " - " + displayBirthday + "\n");
}
}
VIRTUAL DEVICE------------
Shows black screen and the my app brake down
LOGCAT-----------------
Log/I-Start reading birthdays from contacts
So the problem is in creating the uri
, but it looks like rite)
Best regards, SergaRUS