0

在我的 LG-G3 上有一个名为“电话”的默认日历。这不是谷歌的。

我构建了一个将事件与用户的 Google 日历同步的应用程序,但是当我选择所有带有查询的日历时 - 我也得到了“电话”日历。由于它不是 Google 日历,因此我无法将其与 Google 日历功能(插入、删除等)一起使用。

除了名称之外,我看不出“电话”日历和 Google canledars 之间有什么不同。有什么方法可以知道日历是否属于 Google 的?

这是我的查询:

        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) {
            // ...
        }
4

1 回答 1

1

谷歌日历可以通过查看日历ID的域名来识别。对于主日历,日历 ID 域名为 @gmail.com。如果它的辅助日历,日历ID域名是group.calendar.google.com

于 2015-03-16T15:38:42.190 回答