我希望事件来自android日历特定日期的arrayList事件。但是得到事件的一些时间光标显示0结果和一段时间它显示完美的结果。帮助显示我的以下代码并帮助我。
用于获取特定日期事件的arrayList循环
for (int i = 0; i < mListCalendarData.size(); i++) {
readCalendarEvent(mHomeActivity, mSharedPreferencesCustom.getString(SharedPreferencesConstant.PREF_ACCOUNT_NAME, ""),
getYearOnly(mListCalendarData.get(i).getDate()),
getMonthOnly(mListCalendarData.get(i).getDate()),
getDateOnly(mListCalendarData.get(i).getDate()),
getHoursOnly(mListCalendarData.get(i).getTime()),
getMinteOnly(mListCalendarData.get(i).getTime()),
getAOnly(mListCalendarData.get(i).getTime()),
mListCalendarData.get(i).getTitle());
}
这是阅读日历活动的功能。
public boolean readCalendarEvent(final Context context, final String AccountName, final int year, final int month, final int date, final int hours, final int mint, final int A, final String APITitle) {
isEventAdded = false;
try {
ContentResolver contentResolver = context.getContentResolver();
String[] projection = new String[]{CalendarContract.Events.CALENDAR_ID, CalendarContract.Events.TITLE, CalendarContract.Events.DESCRIPTION, CalendarContract.Events.DTSTART, CalendarContract.Events.DTEND, CalendarContract.Events.OWNER_ACCOUNT, CalendarContract.Events._ID, CalendarContract.Events.ALL_DAY, CalendarContract.Events.EVENT_LOCATION};
Calendar c_start = Calendar.getInstance();
c_start.set(year, month, date, 01, 00, 00); //Note that months start from 0 (January)
Calendar endTime = Calendar.getInstance();
endTime.set(year, month, date, 23, 59, 59);
String selection = "(( " +CalendarContract.Events.CALENDAR_ID +" == "+calId+" ) AND (" + CalendarContract.Events.DTSTART + " >= " + c_start.getTimeInMillis() + " ) AND ( " + CalendarContract.Events.DTEND + " <= " + endTime.getTimeInMillis() + " ) AND ( deleted != 1 ))";
final Cursor cursor = contentResolver.query(Uri.parse("content://com.android.calendar/events"), projection, selection, null, "dtstart ASC");
System.out.println("Cursor size====================>" + cursor.getCount());
if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
do {
Log.i("CalanderStaff", "CALENDAR_ID: " + cursor.getString(0));
Log.i("CalanderStaff", "title: " + cursor.getString(1));
Log.i("CalanderStaff", "CalendarTime: " +cursor.getString(3));
Log.i("CalanderStaff", "Account : " + cursor.getString(5));
Log.i("CalanderStaff", "ID : " + cursor.getString(6));
Log.i("CalanderStaff", "Our account : " + AccountName);
} while (cursor.moveToNext());
} else {
Log.i("CalanderStaff", "No event for this date .. cursor 0");
}
cursor.close();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
请帮我解决这个问题。谢谢。