开发者

How to retrieve all reminders which are added in calendar in android?

开发者 https://www.devze.com 2023-03-25 06:07 出处:网络
I am new in Android. I want to retrieve all reminders which are added in calendar. How can I get all reminders/events?

I am new in Android. I want to retrieve all reminders which are added in calendar. How can I get all reminders/events? I want to display that all reminders 开发者_Go百科in the list.

Please help me I am stuck on this.

Thanks.


I found my mistake, I want to share that so that another will not be suffered. In this we have to more focus on URI. For that we have to write "content://com.android.calendar/events" instead of "content://calendar/events".

I hope anyone will get help from this.

I post here code for more understanding..

Thanks.

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


try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消