开发者

Android: how to detect which Google calendars are synced with the device?

开发者 https://www.devze.com 2023-01-24 02:55 出处:网络
I\'m writing a software that checks events in user\'s calendars and does开发者_Go百科 some manipulations over them. But I would like to touch only those events which are present in synced calendars on

I'm writing a software that checks events in user's calendars and does开发者_Go百科 some manipulations over them. But I would like to touch only those events which are present in synced calendars only. I'm using Google Calendar API, but don't know how to list only synced calendars and ignore others.

Thanks


There is no concept of "synced calendars" with respect to the Android SDK. Some applications might sync calendars, such as the Calendar app that is part of the Android open source project. However, that particular app may or may not exist on any given phone, and it has no documented and supported APIs.


Actually, you have two options here.

You can check the accounts synced with the device, then verify if those accounts are also Google Accounts that are syncing their respective calendars to the device.

The below will provide you all the accounts registered to the device (typically Google Accounts of some sort). If you want all accounts, regardless of whether they are Google or not, use AccountManager.getAccounts() instead.

Account[] theAccounts = AccountManager.getAccountsByType("com.google");

You have to get your AccountManager via getSystemService(Context.ACCOUNT_SERVICE) first.

To get access to the calendars synced on the device, read "synced" as active, you can use the GData API (which I have never been able to get working properly), or access to the local sqllite database that stores the calendar(s) directly on the device.

Without posting tons of code on how to access that database, if you do a search for "android accessing calendar database", you should find lots of useful information on accessing that database.

Good starting point: Getting events from calendar

I have this working on an app that I am writing - checking local/synced accounts, then pulling that data out of the internal database and grabbing the calendars just for the local accounts versus all calendars on the device. I have lots of calendars shared with me from work, so I only want the calendars "local" to the device for my app.


Old question, but I thought I'd update in case someone comes across it. As of SDK 14 you can use SYNC_EVENTS in your query().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号