如何为谷歌日历构建同步适配器?
我正在为学生构建一个应用程序来管理大学课程。
现在我想将事件(事件有日期和时间以及简短的描述)与Android的谷歌日历同步。
我查看了 Android 示例中的samplesync 适配器,但我没有发现它对日历很有用。
应通过复选框从应用程序的设置中启用和禁用应用程序的同步。
有人有一些有用的示例代码吗?
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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
android.preference.PreferenceActivity
来制作您的首选项页面。确保您的应用在打开之前使用系统中的值更新首选项页面上的复选框。 (该设置可能已在“帐户和同步”系统控制面板中更改。)使用
ContentResolver.getSyncAutomatically(Account account, String Authority)
读取系统值命令系统匹配使用
ContentResolver.setSyncAutomatically(Account account, Stringauthority, booleansync) 设置 PreferenceActivity
--请注意,您无法控制提供程序上的同步 -- 您可以为帐户/提供程序对控制它。您的应用程序需要保留其设置使用的帐户的副本,以便可以在这些调用中传递它。
Use
android.preference.PreferenceActivity
to make your preference page.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 valueCommand 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.