【发布时间】:2014-03-16 07:48:00
【问题描述】:
我需要获取联系人的生日,但我的代码不起作用
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");
}
}
虚拟设备------------
显示黑屏和我的应用程序停止
LOGCAT-----
Log/I-Start reading birthdays from contacts
所以问题在于创建uri,但它看起来像仪式)
最好的问候,SergaRUS
【问题讨论】: