Используя контент-провайдера, вы можете получить доступ к календарным событиям. Для получения данных провайдера контента используется метод распознавателя контента (). Вам нужно передать список столбцов, которые нужно получить.
Вы можете получить ссылки из документации по календарю для Android, проверьте ссылку ниже https://developer.android.com/reference/java/util/Calendar
// add below permission in your manifest file and ask these permission at run time also
<uses-permission android:name="android.permission.WRITE_CALENDAR"></uses-permission>
<uses-permission android:name="android.permission.READ_CALENDAR"></uses-permission>
public void getDataFromEventsTable() {
Cursor cur = null;
ContentResolver cr =getContentResolver();
//if you want access calendar details use below uri
// Uri uri = CalendarContract.Calendars.CONTENT_URI;
String[] calmProjection ={CalendarContract.Calendars._ID,
CalendarContract.Calendars.ACCOUNT_NAME,
CalendarContract.Calendars.ACCOUNT_TYPE,
CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
CalendarContract.Calendars.CALENDAR_COLOR,
CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL,
CalendarContract.Calendars.OWNER_ACCOUNT,
CalendarContract.Calendars.CALENDAR_TIME_ZONE,
CalendarContract.Calendars.ALLOWED_REMINDERS};
//if your want access event related info use below uri
Uri uri=CalendarContract.Events.CONTENT_URI;
String[] eventmProjection =
{CalendarContract.Calendars._ID,
CalendarContract.Events.DTSTART,
CalendarContract.Events.DTEND,
CalendarContract.Events.TITLE,
CalendarContract.Events.EVENT_LOCATION,
CalendarContract.Events.ORGANIZER,
CalendarContract.Events._ID,
CalendarContract.Events.DESCRIPTION,
CalendarContract.Events.DURATION,
CalendarContract.Events.SYNC_DATA1,
CalendarContract.Events.DIRTY,
CalendarContract.Events.UID_2445,
CalendarContract.Events.DELETED,
CalendarContract.Events.LAST_DATE,
CalendarContract.Events.SYNC_DATA2,
CalendarContract.Events.ALL_DAY,
CalendarContract.Events.RRULE,
CalendarContract.Events.STATUS,
CalendarContract.Events.RDATE
};
String selection = "((" + CalendarContract.Calendars.ACCOUNT_NAME + " = ?) AND ("
+ CalendarContract.Calendars.ACCOUNT_TYPE + " = ?) AND ("
+ CalendarContract.Calendars.OWNER_ACCOUNT + " = ?))";
// pass here details of account, which account linked with your google calendar
String[] selectionArgs = new String[]{"xyz@gmail.com", "com.google",
"xyz@gmail.com"};
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CALENDAR},12);
}
cur = cr.query(uri, eventmProjection, selection, selectionArgs, null);
if(cur.getCount()>0){
while (cur.moveToNext()) {
String eventTitle = cur.getString(cur.getColumnIndex(CalendarContract.Events.TITLE));
String eventId = cur.getString(cur.getColumnIndex(CalendarContract.Events._ID));
String startDate = cur.getString(cur.getColumnIndex(CalendarContract.Events.DTSTART));
String endDate = cur.getString(cur.getColumnIndex(CalendarContract.Events.DTEND));
Log.d("Events", "->" + eventTitle + "->" + eventId + "->" + startDate + "->" + endDate);
}
}
}