내 문제에 대한 답변을 찾는 데 꽤 오랜 시간이 걸렸습니다. 내가 원하는 일 : 당일의 모든 캘린더에서 모든 일정 가져 오기오늘의 Android 4.0 이상에서 모든 캘린더 이벤트 받기
전 ICS 장치 (2.2 ~ 3.2 안드로이드 버전)에 문제없이 할 수 있습니다. Android 4.0 이상에서는 새 캘린더 API가 도입 된 이후로 상당히 성공적으로 처리했습니다. 글쎄, 그건 내가 다른 장치를 테스트하기 전에 내가 생각했던 것이다. 때로는 제 코드가 작동하고 때로는 그렇지 않을 수도 있습니다. 반복되는 이벤트는 일부 장치 또는 다른 장치에는 나타나지 않으며 모든 이벤트가 표시됩니다 (현재 날짜뿐 아니라).
나는 문제가 한 줄의 코드에서라고 생각하지만 난 제대로하는 방법을 찾을 수 없습니다 :
: 여기cursor = contentResolver.query(CalendarContract.Events.CONTENT_URI, COLS, "("+CalendarContract.Events.DTSTART+">"+now+" and "+CalendarContract.Events.DTEND+"<"+endOfDay.getTimeInMillis()+") or (("+CalendarContract.Events.ALL_DAY+"=1) and "+"("+CalendarContract.Events.DTSTART+">="+timeAllDay.getTimeInMillis()+") and "+"("+CalendarContract.Events.DTEND+"<="+endTimeAllDay.getTimeInMillis()+"))", null, null);
내가 위의 선으로 생성 된 모든 클래스
public class ICSCalendar extends AsyncTask<Intent, String, Intent>
{
private static final String[] COLS = new String[] {CalendarContract.Events.TITLE, CalendarContract.Events.DTSTART, CalendarContract.Events.DTEND, CalendarContract.Events.ALL_DAY};
@Override
protected Intent doInBackground(Intent... params)
{
ContentResolver contentResolver = Alert.mContext.getContentResolver();
Cursor cursor = null;
try
{
long now = new Date().getTime();
Calendar endOfDay = Calendar.getInstance();
endOfDay.set(Calendar.HOUR_OF_DAY, 23);
endOfDay.set(Calendar.MINUTE, 59);
endOfDay.set(Calendar.SECOND, 59);
Calendar timeAllDay = Calendar.getInstance();
timeAllDay.set(Calendar.HOUR_OF_DAY, 0);
timeAllDay.set(Calendar.MINUTE, 0);
timeAllDay.set(Calendar.SECOND, 0);
Calendar endTimeAllDay = Calendar.getInstance();
endTimeAllDay.add(Calendar.DAY_OF_MONTH, 1);
endTimeAllDay.set(Calendar.HOUR_OF_DAY, 2);
endTimeAllDay.set(Calendar.MINUTE, 0);
endTimeAllDay.set(Calendar.SECOND, 1);
cursor = contentResolver.query(CalendarContract.Events.CONTENT_URI, COLS, "("+CalendarContract.Events.DTSTART+">"+now+" and "+CalendarContract.Events.DTEND+"<"+endOfDay.getTimeInMillis()+") or (("+CalendarContract.Events.ALL_DAY+"=1) and "+"("+CalendarContract.Events.DTSTART+">="+timeAllDay.getTimeInMillis()+") and "+"("+CalendarContract.Events.DTEND+"<="+endTimeAllDay.getTimeInMillis()+"))", null, null);
Intent calendarData = new Intent(Alerts.CALENDAR_UI_DATA);
int nb_events = 0;
while(cursor.moveToNext())
{
nb_events++;
final String title = cursor.getString(0);
final Date begin = new Date(cursor.getLong(1));
final Boolean allDay = !cursor.getString(3).equals("0");
calendarData.putExtra("event_"+nb_events, (String) title);
calendarData.putExtra("all_day_event_"+nb_events, (Boolean) allDay);
Calendar beginEvent = Calendar.getInstance();
beginEvent.setTimeInMillis(cursor.getLong(1));
String format = Alerts.get24HourMode(Alert.mContext) ? "kk:mm": "h:mm";
CharSequence newTime = DateFormat.format(format, beginEvent);
if(format == "h:mm")
{
if((beginEvent.get(Calendar.AM_PM) == 0))
{
newTime = newTime + " A.M";
}
else
{
newTime = newTime + " P.M";
}
}
if(!allDay)
{
calendarData.putExtra("date_event_"+nb_events, newTime);
}
else
{
calendarData.putExtra("date_event_"+nb_events, Alert.mContext.getString(R.string.tts_whole_day_calendar_event));
}
}
calendarData.putExtra("nb_events", nb_events);
return calendarData;
}
catch(Exception e)
{
Log.d("DEBUG", ""+e);
return null;
}
}
@Override
protected void onPostExecute(Intent result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
try
{
Alert.mContext.sendBroadcast(result);
}
catch(NullPointerException e){}
}
@Override
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values)
{
// TODO Auto-generated method stub
super.onProgressUpdate(values);
}
}
사람은 안드로이드 4.0 이상에 대한 현재의 일에 대한 모든 캘린더의 모든 이벤트를 얻는 방법의 아이디어가있다? 모든 도움을 감사합니다 :)