How to identify Drive ID?

青春壹個敷衍的年華 提交于 2019-12-18 09:24:21

问题


The new Google Drive Android API has 2 types of string IDs available, the 'resource' ID and the 'encoded' ID.

'encoded' id from DriveId.encodeToString()
"DriveId:CAESHDBCMW1RVVcyYUZKZmRhakIzMDBVbXMYjAUgssy8yYFRTTNKRU55"

'resource' id from DriveId.getResourceId()
"UW2aFJfdajB3M3JENy00Ums0B1mQ"

In the process I end-up with a string that can contain any one of them (result of some timing issues). My question is:

If I need to 'parse' the string in order to identify the type, is there a characteristic I can rely on? For instance:

  • 'encoded' id will always start with 'DriveId:' substring
  • 'resource' id will have some length limit
  • can I abuse error return from 'decodeFromString()'?
  • or should I form (pre-pend) the string container with my own tag? What could be the minimal 'safe' tag (i.e. what will never appear in the beginning of these ids) ?

Please point me in the right direction so I don't have to re-do it with the next release.

I have run into yet another issue that should be mentioned here so others don't waste time falling into the same pit. The 'resourceID' can be ported and will remain unique for the object it identifies, where 'encodedID' has only 'device' scope. Means that you CAN'T transfer 'encodedID' to another device (with the same account) and try to retrieve file/folder with it. So I assume it is unique to a Google Play Services instance.


回答1:


Please do not rely on any formatting of either ID type. This are subject to change without notice.

If you need to use both, and track the differences between them you should have your own method of doing so within your app.

Really, you should probably always just store the encoded ID since this one is always guaranteed to present, and if it contains a resourceId, its easy to get back out.



来源:https://stackoverflow.com/questions/22841237/how-to-identify-drive-id

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