java制作android 日历代码分享
代码很简单,就不多废话了
//读取日历事件 publicstaticvoidgetCalendarInfo(Activityactivity,Stringtag){ String[]projection=newString[]{CalendarContract.Events._ID,CalendarContract.Events.TITLE}; ContentResolvercr=activity.getContentResolver(); Cursorcursor=cr.query(CalendarContract.Events.CONTENT_URI,projection,null,null,null); intidIndex=cursor.getColumnIndexOrThrow(CalendarContract.Events._ID); Log.d(tag,cursor.getCount()+""); inttitleIndex=cursor.getColumnIndexOrThrow(CalendarContract.Events.TITLE); while(cursor.moveToNext()){ Stringid=cursor.getString(idIndex); Stringtitle=cursor.getString(titleIndex); Log.d(tag,id+":"+title); } cursor.close(); } //插入事件 publicstaticvoidaddCalendarEvent(Activityactivity,Stringtag){ Intentintent=newIntent(Intent.ACTION_INSERT,CalendarContract.Events.CONTENT_URI); Log.d(tag,CalendarContract.Events.CONTENT_URI.toString()); intent.putExtra(CalendarContract.Events.TITLE,"Launch"); intent.putExtra(CalendarContract.Events.DESCRIPTION,"Launch,Androidapp"); intent.putExtra(CalendarContract.Events.EVENT_LOCATION,"baidu.com"); Calendarcalendar=Calendar.getInstance(); calendar.setTime(newDate()); intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,calendar.getTimeInMillis()); intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY,true); activity.startActivity(intent); } //编辑日历事件 publicstaticvoideditCalendarEvent(Activityactivity,Stringtag){ longrowId=1; UrieditUri=ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI,rowId); Log.d(tag,CalendarContract.Events.CONTENT_URI.toString()); Intentintent=newIntent(Intent.ACTION_EDIT,editUri); intent.putExtra(CalendarContract.Events.EVENT_LOCATION,"NJ"); Calendarcalendar=Calendar.getInstance(); calendar.set(2015,2,17,12,1,1); intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,calendar.getTimeInMillis()); intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY,true); activity.startActivity(intent); } //查看日历 publicstaticvoidviewCalendar(Activityactivity,Stringtag){ Calendarcalendar=Calendar.getInstance(); calendar.set(2015,2,17,12,1,1); Uriuri=Uri.parse("content://com.android.calendar/time/"+calendar.getTimeInMillis()); Intentintent=newIntent(Intent.ACTION_VIEW,uri); activity.startActivity(intent); }
以上就是本文给大家分享的全部代码了,希望对大家学习java能够有所帮助。