如何检索在android中的日历中添加的所有提醒?

时间:2011-08-05 06:37:35

标签: android

我是Android新手。我想要检索日历中添加的所有提醒。如何获取所有提醒/事件? 我想在列表中显示所有提醒。

请帮助我,我坚持这个。

感谢。

2 个答案:

答案 0 :(得分:2)

我发现了自己的错误,我希望与大家分享,以免另一个人受苦。在此我们必须更多地关注URI。为此,我们必须编写“ content://com.android.calendar/events ”而不是“ content:// calendar / events ”。

我希望有人能从中得到帮助。

我在这里发布代码以便更加了解..

感谢。

  final ContentResolver cr = this.getContentResolver();
        try
        {
            cursor = cr.query(Uri.parse("content://com.android.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);

            Log.i("Sample Activity", "Cursor size " +cursor.getCount());
            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);
                Log.i("SAmple Reminder****", "events from calendar "+ add);
                cursor.moveToNext();
               }
               cursor.close();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

        cursor.close();

答案 1 :(得分:1)

试试这个:

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();