Android Google DriveApi returning different DriveID for same title on different devices

你说的曾经没有我的故事 提交于 2019-12-05 21:35:22
seanpj

Unfortunately, I got lost in your specific case explanation, but if I only read the headline, I can give you some clues, since I ran into the same problem.

There are 2 ID's for each object (folder, or file) in GDAA (Google Drive Android Api), the DRIVE_ID and the RESOURCE_ID.

The DRIVE_ID identifier is specific to your particular device, so if you use it on another device, it means nothing. The RESOURCE_ID is unique across devices, so that's the one you need to use for any type of synchronization. See SO 22841237.

If you create a file/folder using GDAA, the RESOURCE_ID may not be immediately available, since GDAA needs to 'commit' the object to get it. See SO 22432431.

DO NOT use file/folder title (name) at all, since it is not a primary ID in the Google Drive world. You can have multiple Drive objects in the same area with the same title (name).

Also, be aware of the fact, that adding GDAA to the equation (as opposed to using plain RESTful API), you are adding a layer that has its own latency you have no control over. The 'ChangeEvent Listener' and 'requestSync()' are no help either. See SO 23073474.

Just to give you a hint, after spending a few months fighting the same issues, I rolled back to the RESTful API, with data provider and sync adapter, polling Drive for changes. The next step will be to add GCM-based synchronization. I was hoping the sync (using GCM) would be built-in the GDAA. But it apparently is not. And you haven't tried to delete files/folders yet, that's where the real fun begins.

Good Luck.

Does setting up the appFolder like this help?

String appFolder = Drive.DriveApi.getAppFolder(mGoogleApiClient()).getDriveId().getResourceId().toString();

I was having the same issue (duplicated folders) and I solved using requestSync BEFORE running the search query:

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