Source:
public void getCalendarData() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_CALENDAR}, MY_CAL_REQ); } else { Uri calendarUri; if (Integer.parseInt(Build.VERSION.SDK) >= 8 || Integer.parseInt(Build.VERSION.SDK) <= 13) { calendarUri = Uri.parse("content://com.android.calendar/events"); } else if (Integer.parseInt(Build.VERSION.SDK) >= 14) { calendarUri = CalendarContract.Events.CONTENT_URI; } else { calendarUri = Uri.parse("content://calendar/events"); } Calendar startTime = Calendar.getInstance(); startTime.set(2018, 2, 1, 0, 0); Calendar endTime = Calendar.getInstance(); endTime.set(2018, 6, 1, 0, 0); String selection = "(( " + CalendarContract.Events.DTSTART + " >= " + startTime.getTimeInMillis() + " )" + " AND ( " + CalendarContract.Events.DTSTART + " <= " + endTime.getTimeInMillis() + " ))"; String[] projection = new String[] {CalendarContract.Events.CALENDAR_ID, CalendarContract.Events.TITLE, CalendarContract.Events.EVENT_LOCATION, CalendarContract.Events.DTSTART}; Cursor cur = this.getContentResolver().query(calendarUri, projection, selection, null, null); featureList = new ArrayList<>(); int index = 0; if (cur != null) { while (cur.moveToNext()) { if (index <= 80) { if (!cur.getString(EVENT_LOCATION_INDEX).isEmpty()) { makeMapboxGeocodingRequest(cur.getString(TITLE_INDEX), cur.getString(EVENT_LOCATION_INDEX)); } else { Timber.d("getCalendarData: location.isEmpty()"); } index++; } } setUpData(); } } }

Target:
public void getCalendarData() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_CALENDAR}, MY_CAL_REQ); } else { Uri calendarUri; if (Integer.parseInt(Build.VERSION.SDK) >= 8 && Integer.parseInt(Build.VERSION.SDK) <= 13) { calendarUri = Uri.parse("content://com.android.calendar/events"); } else if (Integer.parseInt(Build.VERSION.SDK) >= 14) { calendarUri = CalendarContract.Events.CONTENT_URI; } else { calendarUri = Uri.parse("content://calendar/events"); } Calendar startTime = Calendar.getInstance(); startTime.set(2018, 2, 1, 0, 0); Calendar endTime = Calendar.getInstance(); endTime.set(2018, 6, 1, 0, 0); String selection = "(( " + CalendarContract.Events.DTSTART + " >= " + startTime.getTimeInMillis() + " )" + " AND ( " + CalendarContract.Events.DTSTART + " <= " + endTime.getTimeInMillis() + " ))"; String[] projection = new String[] {CalendarContract.Events.CALENDAR_ID, CalendarContract.Events.TITLE, CalendarContract.Events.EVENT_LOCATION, CalendarContract.Events.DTSTART}; Cursor cur = this.getContentResolver().query(calendarUri, projection, selection, null, null); featureList = new ArrayList<>(); int index = 0; if (cur != null) { if (!deviceHasInternetConnection()) { Toast.makeText(this, R.string.no_connectivity, Toast.LENGTH_LONG).show(); Timber.d("No internet connectivity"); } else { while (cur.moveToNext()) { if (index <= 80) { if (!cur.getString(EVENT_LOCATION_INDEX).isEmpty()) { makeMapboxGeocodingRequest(cur.getString(TITLE_INDEX), cur.getString(EVENT_LOCATION_INDEX)); } else { Timber.d("getCalendarData: location.isEmpty()"); } index++; } } setUpData(); } } } }