Получить список установленных программ календаря
Как получить список установленных программ календаря и связанных с ними аккаунтов. например у меня установлены гугл календарь,s-planner, outlook
Ответы (1 шт):
Автор решения: Sergei Buvaka
→ Ссылка
Cursor cursor;
if (android.os.Build.VERSION.SDK_INT <= 7) {
cursor = context.getContentResolver().query(Uri.parse("content://calendar/calendars"), new String[]{"_id", "displayName"}, null, null, null);
} else if (android.os.Build.VERSION.SDK_INT <= 14) {
cursor = context.getContentResolver().query(Uri.parse("content://com.android.calendar/calendars"),
new String[]{"_id", "displayName"}, null, null, null);
} else {
cursor = context.getContentResolver().query(Uri.parse("content://com.android.calendar/calendars"),
new String[]{"_id", "calendar_displayName"}, null, null, null);
}
// Get calendars name
if (cursor.getCount() > 0) {
cursor.moveToFirst();
String[] calendarNames = new String[cursor.getCount()];
// Get calendars id
int calendarIds[] = new int[cursor.getCount()];
for (int i = 0; i < cursor.getCount(); i++) {
calendarIds[i] = cursor.getInt(0);
calendarNames[i] = cursor.getString(1);
Log.i("Calendar Name : " + calendarNames[i]);
cursor.moveToNext();
}
} else {
Log.e("No calendar found in the device");
}
Для этого вам нужно использовать ContentResolver. Предварительно вы должна получить Permissions READ_CALENDAR & WRITE_CALENDAR.
Еще вам стоит почитать документацию про Calendar Provider. Там так же есть примеры кода и в целом описание того как это работает.