我在ICS中创建新日历时遇到问题。日历应该可以与谷歌日历同步。我试着跟随:
Uri calendarUri = CalendarContract.Calendars.CONTENT_URI;
calendar.put(CalendarContract.Calendars.ACCOUNT_NAME, sync_account);
calendar.put(CalendarContract.Calendars.ACCOUNT_TYPE, "com.google");
calendar.put(CalendarContract.Calendars.NAME, name);
calendar.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, displayName);
calendar.put(CalendarContract.Calendars.CALENDAR_COLOR, 0xFF008080);
calendar.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
calendar.put(CalendarContract.Calendars.OWNER_ACCOUNT, true);
calendar.put(CalendarContract.Calendars.VISIBLE, 1);
calendar.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
calendarUri = calendarUri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, sync_account)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, "com.google") // CalendarContract.ACCOUNT_TYPE_LOCAL
.build();
Uri result = activity.getContentResolver().insert(calendarUri, calendar);
我总是得到这个错误(编辑:不再):
09-17 17:11:30.278: E/AndroidRuntime(13243): FATAL EXCEPTION: CalendarSyncAdapterAccountMonitor
09-17 17:11:30.278: E/AndroidRuntime(13243): java.lang.IllegalArgumentException: the name must not be empty: null
09-17 17:11:30.278: E/AndroidRuntime(13243): at android.accounts.Account.<init>(Account.java:48)
09-17 17:11:30.278: E/AndroidRuntime(13243): at com.google.android.syncadapters.calendar.CalendarSyncAdapter.onAccountsUpdated(CalendarSyncAdapter.java:1129)
09-17 17:11:30.278: E/AndroidRuntime(13243): at android.accounts.AccountManager$11.run(AccountManager.java:1279)
09-17 17:11:30.278: E/AndroidRuntime(13243): at android.os.Handler.handleCallback(Handler.java:605)
09-17 17:11:30.278: E/AndroidRuntime(13243): at android.os.Handler.dispatchMessage(Handler.java:92)
09-17 17:11:30.278: E/AndroidRuntime(13243): at android.os.Looper.loop(Looper.java:137)
09-17 17:11:30.278: E/AndroidRuntime(13243): at android.os.HandlerThread.run(HandlerThread.java:60)
09-17 17:11:30.293: E/android.os.Debug(1989): !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error
如何使用CalendarSyncAdapterAccountMonitor,它不是空的?
提前致谢。
修改
我忘记插入时区,而不是完全没有错误:
calendar.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, TimeZone.getDefault().getID());
如果我创建了可同步日历(上面的代码snippset),只需注意,没有错误,也没有创建日历。
如果我将其更改为lokal(请参阅下文),即使可以添加事件,也可以毫无错误地创建日历。我能做些什么,可以创建可同步的日历?
Uri calendarUri = CalendarContract.Calendars.CONTENT_URI;
calendar.put(CalendarContract.Calendars.ACCOUNT_NAME, sync_account);//
//calendar.put(CalendarContract.Calendars.ACCOUNT_TYPE, "com.google");
calendar.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
calendar.put(CalendarContract.Calendars.NAME, name);
calendar.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, name);
calendar.put(CalendarContract.Calendars.CALENDAR_COLOR, 0xFF008080);
calendar.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
calendar.put(CalendarContract.Calendars.OWNER_ACCOUNT, sync_account);// true
calendar.put(CalendarContract.Calendars.VISIBLE, 1);
calendar.put(CalendarContract.Calendars.SYNC_EVENTS, 1); // 1 for syncable, 0 for local
//calendar.put(CalendarContract.Calendars.DIRTY, 0);
calendar.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, TimeZone.getDefault().getID());
calendarUri = calendarUri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, sync_account)//
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL) // "com.google"
.build();
Uri result = activity.getContentResolver().insert(calendarUri, calendar);
答案 0 :(得分:1)
您也可以手动创建新日历,并使用以下内容解析应用中的日历:
Uri.parse("content://com.android.calendar/calendars",null, null, null, null);
找到正确的日历ID后,您只需添加/更新事件即可。这个事件将是可以同步的。
答案 1 :(得分:1)
请检查此链接..他说,这是一个来自android Os方面的问题
http://dmfs.org/wiki/index.php?title=Sync_errors_and_possible_reasons