0

On my LG-G3 there is a default calendar named "Phone". It's not Google's.

I build an application which syncs events with the user's Google Calendars, but when I select all the calendars with a query - I get the "Phone" calendar too. Since it's not a Google calendar, I can't use it with the Google Calendar functions (insert, delete, etc.).

I can't see any different between "Phone" calendar and Google canledars except of its name. Is there any way to know if a calendar is Google's or not?

This is my query:

        String[] l_projection = new String[] { Calendars._ID, Calendars.CALENDAR_DISPLAY_NAME, Calendars.CALENDAR_ACCESS_LEVEL, Calendars.ALLOWED_REMINDERS, Calendars.SYNC_EVENTS };
        Uri l_calendars;
        if (Build.VERSION.SDK_INT >= 8) {
            l_calendars = Uri.parse("content://com.android.calendar/calendars");
        } else {
            l_calendars = Uri.parse("content://calendar/calendars");
        }

        try {
            Cursor l_managedCursor = activity.getContentResolver().query(l_calendars, l_projection, null, null, null); 
            if (l_managedCursor.moveToFirst()) {
                String l_methodAllow;
                String l_accessPermission;
                String l_calName;
                String l_calId;
                String l_syncEvents;
                int l_cnt = 0;
                int l_syncEventsCol = l_managedCursor.getColumnIndex(l_projection[4]);
                int l_methodAllowCol = l_managedCursor.getColumnIndex(l_projection[3]);
                int l_accessPermissionCol = l_managedCursor.getColumnIndex(l_projection[2]);
                int l_nameCol = l_managedCursor.getColumnIndex(l_projection[1]);
                int l_idCol = l_managedCursor.getColumnIndex(l_projection[0]);
                do {
                    String access = l_managedCursor.getString(l_accessPermissionCol);
                    if (access.equals("500") || access.equals("600") || access.equals("700") || access.equals("800")) {
                        l_syncEvents = l_managedCursor.getString(l_syncEventsCol);
                        l_methodAllow = l_managedCursor.getString(l_methodAllowCol);
                        l_accessPermission = l_managedCursor.getString(l_accessPermissionCol);
                        l_calName = l_managedCursor.getString(l_nameCol);
                        l_calId = l_managedCursor.getString(l_idCol);

                        calNames.add(l_calName);
                        // ....

                        ++l_cnt;
                    }
                } while (l_managedCursor.moveToNext());
            }
        } catch (Exception e) {
            // ...
        }
TamarG
  • 3,522
  • 12
  • 44
  • 74
  • 1
    Google calendar can be identified by looking at the domain name of the Calendar ID. For primary calendar, calendar ID domain name is @gmail.com. If its secondary calendar, calendar ID domain name is group.calendar.google.com – SGC Mar 13 '15 at 20:00
  • @SGC - you can post it as an answer – TamarG Mar 15 '15 at 12:26
  • Thanks @TamarG. I posted the answer :) – SGC Mar 16 '15 at 15:43

1 Answers1

1

Google calendar can be identified by looking at the domain name of the Calendar ID. For primary calendar, calendar ID domain name is @gmail.com. If its secondary calendar, calendar ID domain name is group.calendar.google.com

SGC
  • 1,025
  • 1
  • 6
  • 6