我在創建ICS中的新日曆時遇到問題。日曆應該可以與Google日曆同步。我嘗試以下操作:在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): [email protected] > 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);
檢查所有使用非空變量。我們不能看到,在代碼片段 – Tom