How to build a syncadapter for the google calendar?

。_饼干妹妹 提交于 2019-12-06 12:28:37

问题


I'm building an application for students to manage the courses of a university.

Now I would like to synchronize the events (an event has a date and time and a brief description) with the google calendar of Android.

I took a look at the samplesync adapter from the Android sample, but I didn't find it very useful for the calendar.

The sync of the app should be enabled and disabled from the settings of the app with a checkbox.

Does anyone has some sample code that can be useful??


回答1:


  1. Use android.preference.PreferenceActivity to make your preference page.

  2. Ensure that your app updates the checkbox on the preference page with the value from the system before it opens. (The setting may have been changed in the Accounts & Sync system control panel.) Use ContentResolver.getSyncAutomatically(Account account, String authority) to read the system value

  3. Command the system to match the PreferenceActivity setting using ContentResolver.setSyncAutomatically(Account account, String authority, boolean sync) --

Note that you can't control sync on a provider -- you control it for an account/provider pair. Your app will need to keep a copy of the Account it is set to use so it can pass it in these calls.



来源:https://stackoverflow.com/questions/6004255/how-to-build-a-syncadapter-for-the-google-calendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!