admin管理员组文章数量:1122846
I'm trying to do Google Calendar synchronization with iOS and Android.
For iOS i'm using google-api-objectivec-client-for-rest
For Android i'm using the method with contentResolver and ContentValues calendar-provider
I understand that on iOS side is using the Rest API and on the other side on Android is using the content provider.
In order to not duplicate the events i have used the ID from android that is a long value. When i had implemented on iOS, i found out that the ID is a String (very long and not integer).
On iOS i found out:
**
* Opaque identifier of the event. When creating new single or recurring
* events, you can specify their IDs. Provided IDs must follow these rules:
* - characters allowed in the ID are those used in base32hex encoding, i.e.
* lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938
* - the length of the ID must be between 5 and 1024 characters
* - the ID must be unique per calendar Due to the globally distributed nature
* of the system, we cannot guarantee that ID collisions will be detected at
* event creation time. To minimize the risk of collisions we recommend using
* an established UUID algorithm such as one described in RFC4122.
* If you do not specify an ID, it will be automatically generated by the
* server.
* Note that the icalUID and the id are not identical and only one of them
* should be supplied at event creation time. One difference in their semantics
* is that in recurring events, all occurrences of one event have different ids
* while they all share the same icalUIDs.
*
* identifier property maps to 'id' in JSON (to avoid Objective C's 'id').
*
@property(nonatomic, copy, nullable) NSString *identifier;
So it turns out that the ID from rest is an Opaque iD, but the ID from Android is actually a sequence generated by Google after the event creation.
I have tried to search for the Opaque ID from Android side but i'm not able to find it into the docs. And this is probably done on purpose because the ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, googleID)
actually takes a long as ID.
I have found a similar answer here and i have followed it setting a custom UID on Android side for the parameter CalendarContract.Events.UID_2445. (as is not generated automatically even if i try to do a query after the insertion)
UUID.randomUUID().toString()
.replace("-", "")
.lowercase()
But when i try to get the same event from iOS i'm not able to do it because i'm getting error not found.
I have tried to get all the events and columns to see if i can get it by doing a query but actually it's not a field.
For example on android side i have set uID = 62b92a9f626c4a7da7653f7f5c758d04
but on iOS i'm getting this:
This difference between the api was done on purpose?
Should i use rest api on android to get the same thing? I didn't find any out of the box.
How can i synchronize the events between Android and iOS if the events id's generated are different?
I'm trying to do Google Calendar synchronization with iOS and Android.
For iOS i'm using google-api-objectivec-client-for-rest
For Android i'm using the method with contentResolver and ContentValues calendar-provider
I understand that on iOS side is using the Rest API and on the other side on Android is using the content provider.
In order to not duplicate the events i have used the ID from android that is a long value. When i had implemented on iOS, i found out that the ID is a String (very long and not integer).
On iOS i found out:
**
* Opaque identifier of the event. When creating new single or recurring
* events, you can specify their IDs. Provided IDs must follow these rules:
* - characters allowed in the ID are those used in base32hex encoding, i.e.
* lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938
* - the length of the ID must be between 5 and 1024 characters
* - the ID must be unique per calendar Due to the globally distributed nature
* of the system, we cannot guarantee that ID collisions will be detected at
* event creation time. To minimize the risk of collisions we recommend using
* an established UUID algorithm such as one described in RFC4122.
* If you do not specify an ID, it will be automatically generated by the
* server.
* Note that the icalUID and the id are not identical and only one of them
* should be supplied at event creation time. One difference in their semantics
* is that in recurring events, all occurrences of one event have different ids
* while they all share the same icalUIDs.
*
* identifier property maps to 'id' in JSON (to avoid Objective C's 'id').
*
@property(nonatomic, copy, nullable) NSString *identifier;
So it turns out that the ID from rest is an Opaque iD, but the ID from Android is actually a sequence generated by Google after the event creation.
I have tried to search for the Opaque ID from Android side but i'm not able to find it into the docs. And this is probably done on purpose because the ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, googleID)
actually takes a long as ID.
I have found a similar answer here and i have followed it setting a custom UID on Android side for the parameter CalendarContract.Events.UID_2445. (as is not generated automatically even if i try to do a query after the insertion)
UUID.randomUUID().toString()
.replace("-", "")
.lowercase()
But when i try to get the same event from iOS i'm not able to do it because i'm getting error not found.
I have tried to get all the events and columns to see if i can get it by doing a query but actually it's not a field.
For example on android side i have set uID = 62b92a9f626c4a7da7653f7f5c758d04
but on iOS i'm getting this:
This difference between the api was done on purpose?
Should i use rest api on android to get the same thing? I didn't find any out of the box.
How can i synchronize the events between Android and iOS if the events id's generated are different?
Share Improve this question asked yesterday 4bottiglie4bottiglie 5207 silver badges23 bronze badges1 Answer
Reset to default 0Investigating further i found out that on Android side, after the synchronization done with the online calendar, the content resolver returns also the _SYNC_ID
field populated with the same ID as returned from the iOS rest api.
To get it, after the contentResolver.insert
i have registered a ContentObserver for the same URI of the event inserted:
val uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI, values)
val longGoogleID = uri!!.lastPathSegment?.toLongOrNull()
val eventChangeObserver = object : ContentObserver(null)
{
override fun onChange(selfChange: Boolean)
{
super.onChange(selfChange)
val syncID = getEventSyncID(context, longGoogleID)
contentResolver.unregisterContentObserver(this)
}
}
contentResolver.registerContentObserver(uri, true, eventChangeObserver)
And get the sync id with the function:
private fun getEventSyncID(context: Context, longID: Long): String?
{
try
{
val contentResolver = context.contentResolver
val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, longID)
val projection = arrayOf(CalendarContract.Events._ID, CalendarContract.Events._SYNC_ID)
val cursor = contentResolver.query(uri, projection, null, null, null) ?: return null
if (!cursor.moveToFirst()) return null
val eventSyncID = cursor.getString(1)
return eventSyncID
} catch (ex: Exception)
{
println(ex)
}
return null
}
This was most probably needed because the events are not synchronized with Google server in the same moment that are inserted so we have to get them in a second moment.
本文标签: androidGoogle Calendar API Opaque Key String vs Native Event ID longStack Overflow
版权声明:本文标题:android - Google Calendar API Opaque Key String vs Native Event ID long - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283668a1927040.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论