如何阅读添加到日历事件/项? [英] How to read events/entries added to calendar?

查看:105
本文介绍了如何阅读添加到日历事件/项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够添加条目截至目前。在我的应用程序,用户可以在他的日历输入约会/事件。但在此之前,他能做到这一点,就应该告诉他,他已经增加的事件。它应该从获取日历事件,并将其展示给他看。如何做到这一点?我停留在这一部分。
先谢谢了。


解决方案

 光标光标= cr.query(Uri.parse(内容://日历/事件),新的String [] {CALENDAR_ID,标题,说明,DTSTART,DTEND,eventLocation},NULL,NULL,NULL);
    //光标指针= cr.query(Uri.parse(内容://日历/日历),新的String [] {_id,姓名},NULL,NULL,NULL);
    字符串添加= NULL;
    cursor.moveToFirst();
    的String [] = CalNames新的String [cursor.getCount()];
    INT [] = CalIds新INT [cursor.getCount()];
    的for(int i = 0; I< CalNames.length;我++){
        CalIds [I] = cursor.getInt(0);
        CalNames [I] =事件+ cursor.getInt(0)+:\\ n标题:+ cursor.getString(1)+\\ n描述:+ cursor.getString(2)+\\ n开始日期:+新的日期(cursor.getLong(3))+\\ NEND日期:+新的日期(cursor.getLong(4))+\\ n位置:+ cursor.getString(5);
        如果(添加== NULL)
            添加= CalNames [I]
        其他{
            添加+ = CalNames [I]
        }
        ((的TextView)findViewById(R.id.calendars))的setText(添加);        cursor.moveToNext();
    }
    cursor.close();

这将读取日历项。

I am able to add entries as of now. In my app, the user can enter an appointment/event on his calendar. But before he can do that, it should show him the events he has already added. it should fetch the events from calendar and show it to him. How to do this? I am stuck at this part. Thanks in advance.

解决方案

Cursor cursor = cr.query(Uri.parse("content://calendar/events"), new String[]{ "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation" }, null, null, null);         
    //Cursor cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id", "name" }, null, null, null);
    String add = null;
    cursor.moveToFirst();
    String[] CalNames = new String[cursor.getCount()];
    int[] CalIds = new int[cursor.getCount()];
    for (int i = 0; i < CalNames.length; i++) {
        CalIds[i] = cursor.getInt(0);
        CalNames[i] = "Event"+cursor.getInt(0)+": \nTitle: "+ cursor.getString(1)+"\nDescription: "+cursor.getString(2)+"\nStart Date: "+new Date(cursor.getLong(3))+"\nEnd Date : "+new Date(cursor.getLong(4))+"\nLocation : "+cursor.getString(5);
        if(add == null)
            add = CalNames[i];
        else{
            add += CalNames[i];
        }           
        ((TextView)findViewById(R.id.calendars)).setText(add);

        cursor.moveToNext();
    }
    cursor.close();

This will read the calendar entries.

这篇关于如何阅读添加到日历事件/项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆