如何获得访问日历上的Android手机? [英] How to get access to the calendars on a Android phone?
本文介绍了如何获得访问日历上的Android手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我给了一些试图访问日历上的Android手机,但没有我的code的工作,有没有有人确切地知道,如何为读/查询日历事件在规定的时间范围内?
解决方案
的String []投影=新的String [] {CalendarContract.Events.CALENDAR_ID,CalendarContract.Events.TITLE,CalendarContract。 Events.DESCRIPTION,CalendarContract.Events.DTSTART,CalendarContract.Events.DTEND,CalendarContract.Events.ALL_DAY,CalendarContract.Events.EVENT_LOCATION};
// 0 =月1 =日,...
日历的startTime = Calendar.getInstance();
startTime.set(2014,00,01,00,00);
日历endTime的= Calendar.getInstance();
endTime.set(2015,00,01,00,00);
//范围是从2014年的所有数据
串选择=((+ CalendarContract.Events.DTSTART +> =+ startTime.getTimeInMillis()+)和(+ CalendarContract.Events.DTSTART +< =+ endTime.getTimeInMillis()+ ));
光标光标= this.getBaseContext()getContentResolver()查询(CalendarContract.Events.CONTENT_URI,投影,选择,NULL,NULL);
//输出事件
如果(cursor.moveToFirst()){
做 {
Toast.makeText(this.getApplicationContext(),标题:+ cursor.getString(1)+开始时间:+(新的日期(cursor.getLong(3)))的toString(),Toast.LENGTH_LONG) 。显示();
}而(cursor.moveToNext());
}
I gave some tries to access the calendars on a Android phone, but none of my code worked, is there someone that knows for sure, how to read/query the calendar events for a specified time range?
解决方案
String[] projection = new String[] { CalendarContract.Events.CALENDAR_ID, CalendarContract.Events.TITLE, CalendarContract.Events.DESCRIPTION, CalendarContract.Events.DTSTART, CalendarContract.Events.DTEND, CalendarContract.Events.ALL_DAY, CalendarContract.Events.EVENT_LOCATION };
// 0 = January, 1 = February, ...
Calendar startTime = Calendar.getInstance();
startTime.set(2014,00,01,00,00);
Calendar endTime= Calendar.getInstance();
endTime.set(2015,00,01,00,00);
// the range is all data from 2014
String selection = "(( " + CalendarContract.Events.DTSTART + " >= " + startTime.getTimeInMillis() + " ) AND ( " + CalendarContract.Events.DTSTART + " <= " + endTime.getTimeInMillis() + " ))";
Cursor cursor = this.getBaseContext().getContentResolver().query( CalendarContract.Events.CONTENT_URI, projection, selection, null, null );
// output the events
if (cursor.moveToFirst()) {
do {
Toast.makeText( this.getApplicationContext(), "Title: " + cursor.getString(1) + " Start-Time: " + (new Date(cursor.getLong(3))).toString(), Toast.LENGTH_LONG ).show();
} while ( cursor.moveToNext());
}
这篇关于如何获得访问日历上的Android手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文