1

I want event from android calendar specific date wise of arrayList. but getting issue some time cursor of getting event show 0 result and some time its show prefect result. help show my following code and help me.

loop for arrayList for fetching specific date wise event

for (int i = 0; i < mListCalendarData.size(); i++) {
           readCalendarEvent(mHomeActivity, mSharedPreferencesCustom.getString(SharedPreferencesConstant.PREF_ACCOUNT_NAME, ""),
                        getYearOnly(mListCalendarData.get(i).getDate()),
                        getMonthOnly(mListCalendarData.get(i).getDate()),
                        getDateOnly(mListCalendarData.get(i).getDate()),
                        getHoursOnly(mListCalendarData.get(i).getTime()),
                        getMinteOnly(mListCalendarData.get(i).getTime()),
                        getAOnly(mListCalendarData.get(i).getTime()),
                        mListCalendarData.get(i).getTitle());
            }

this is function for read calendar event.

public boolean readCalendarEvent(final Context context, final String AccountName, final int year, final int month, final int date, final int hours, final int mint, final int A, final String APITitle) {
        isEventAdded = false;
                try {
                    ContentResolver contentResolver = context.getContentResolver();
                    String[] projection = new String[]{CalendarContract.Events.CALENDAR_ID, CalendarContract.Events.TITLE, CalendarContract.Events.DESCRIPTION, CalendarContract.Events.DTSTART, CalendarContract.Events.DTEND, CalendarContract.Events.OWNER_ACCOUNT, CalendarContract.Events._ID, CalendarContract.Events.ALL_DAY, CalendarContract.Events.EVENT_LOCATION};

                    Calendar c_start = Calendar.getInstance();
                    c_start.set(year, month, date, 01, 00, 00); //Note that months start from 0 (January)

                    Calendar endTime = Calendar.getInstance();
                    endTime.set(year, month, date, 23, 59, 59);

                    String selection = "(( " +CalendarContract.Events.CALENDAR_ID +" == "+calId+" ) AND (" + CalendarContract.Events.DTSTART + " >= " + c_start.getTimeInMillis() + " ) AND ( " + CalendarContract.Events.DTEND + " <= " + endTime.getTimeInMillis() + " ) AND ( deleted != 1 ))";
                    final Cursor cursor = contentResolver.query(Uri.parse("content://com.android.calendar/events"), projection, selection, null, "dtstart ASC");

                            System.out.println("Cursor size====================>" + cursor.getCount());
                            if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
                                do {

                                    Log.i("CalanderStaff", "CALENDAR_ID: " + cursor.getString(0));
                                    Log.i("CalanderStaff", "title: " + cursor.getString(1));
                                    Log.i("CalanderStaff", "CalendarTime: " +cursor.getString(3));
                                    Log.i("CalanderStaff", "Account : " + cursor.getString(5));
                                    Log.i("CalanderStaff", "ID : " + cursor.getString(6));
                                    Log.i("CalanderStaff", "Our account : " + AccountName);
                                } while (cursor.moveToNext());

                            } else {

                                Log.i("CalanderStaff", "No event for this date ..  cursor 0");
                            }
                            cursor.close();

                } catch (Exception e) {
                    e.printStackTrace();
                }
        return true;
    }

Please help me to solve this issue. thank you.

tej shah
  • 2,995
  • 2
  • 25
  • 35
  • Try using the code from the [documentUsing intents to view calendar data](https://developer.android.com/guide/topics/providers/calendar-provider.html#intent-view) using Calendar Provider.You might also want to check this related SO [post](http://stackoverflow.com/a/6175930/5995040) for a more specific example regarding getting the calendar events from android calendar. Hope this helps. – Mr.Rebot Feb 07 '17 at 08:51
  • @Mr.Rebot thank for ans. i tried all most all ex related with specific date getting even. but mostly all have this issue – tej shah Feb 07 '17 at 11:24

0 Answers0