欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java制作android 日历代码分享

程序员文章站 2024-03-03 21:01:58
代码很简单,就不多废话了 复制代码 代码如下: //读取日历事件     public static void getcalendari...

代码很简单,就不多废话了

复制代码 代码如下:

//读取日历事件
    public static void getcalendarinfo(activity activity,string tag){
        string[] projection = new string[]{calendarcontract.events._id,calendarcontract.events.title};
        contentresolver cr = activity.getcontentresolver();
        cursor cursor = cr.query(calendarcontract.events.content_uri, projection, null, null, null);
        int idindex = cursor.getcolumnindexorthrow(calendarcontract.events._id);
        log.d(tag, cursor.getcount()+"");
        int titleindex = cursor.getcolumnindexorthrow(calendarcontract.events.title);
        while (cursor.movetonext()) {
            string id = cursor.getstring(idindex);
            string title = cursor.getstring(titleindex);
            log.d(tag, id+":"+title);
        }
        cursor.close();
    }
    //插入事件
    public static void addcalendarevent(activity activity,string tag){
        intent intent = new intent(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,android app");
        intent.putextra(calendarcontract.events.event_location, "baidu.com");
        calendar calendar = calendar.getinstance();
        calendar.settime(new date());
        intent.putextra(calendarcontract.extra_event_begin_time, calendar.gettimeinmillis());
        intent.putextra(calendarcontract.extra_event_all_day, true);
        activity.startactivity(intent);
    }
    //编辑日历事件
    public static void editcalendarevent(activity activity,string tag){
        long rowid = 1;
        uri edituri = contenturis.withappendedid(calendarcontract.events.content_uri,rowid);
        log.d(tag, calendarcontract.events.content_uri.tostring());
        intent intent = new intent(intent.action_edit,edituri);
        intent.putextra(calendarcontract.events.event_location, "nj");
        calendar calendar = 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);
    }
    //查看日历
    public static void viewcalendar(activity activity,string tag){
        calendar calendar = calendar.getinstance();
        calendar.set(2015, 2, 17, 12, 1, 1);
        uri uri = uri.parse("content://com.android.calendar/time/"+calendar.gettimeinmillis());
        intent intent = new intent(intent.action_view,uri);
        activity.startactivity(intent);
    }

以上就是本文给大家分享的全部代码了,希望对大家学习java能够有所帮助。