Hi, I am using Google Drive Api to store a database using the AppDataFolder tool. My test application works successfully on one device. I can upload / update / delete / upload the database file and reintegrate it into the program without any problems.
The problem I am facing is when I want to share this database with another device using the same application, then everything does not work as expected. Example of device A I load the database, device B - I want to load the database, but the file was not found (this delay can vary greatly from seconds to an hour). The reason for this is that when using Api, it decides when it wants to "synchronize" the data, because it is placed in the queue, and not instantly loaded. Therefore, when used on one device, this is not a problem, because it takes a “synchronized” file from the cloud storage or a file that is waiting for synchronization.
I tried different things, for example, trying to list all the AppDataFolder files or get metadata through a query with filters available for search, before making an update / delete request, etc. However, I can not make it work on my own, basically, it chooses when to synchronize.
So my real question is: how do I get Google Drive to sync my file when I want it, i.e. every time a request is made, so that synchronization is achieved on multiple devices using the same application. There should be an answer, since I think this is a pretty fundamental reason why you would use AppDataFolder - this is the first place.
Thank you in advance
EDIT / UPDATE:
I managed to find an option in Api to synchronize the contents of the disk using this code:
// try to sync Drive.DriveApi.requestSync(mGoogleApiClient).setResultCallback(new ResultCallback<com.google.android.gms.common.api.Status>() { @Override public void onResult(com.google.android.gms.common.api.Status status) { if (!status.getStatus().isSuccess()) { Log.e("SYNCING", "ERROR" + status.getStatusMessage()); } else { Log.e("SYNCING", "SUCCESS"); // execute async task to list AppFolderContents new AppFolderContentsAsyncTask(getActivity()).execute(); } } });
This works well for 3/4 attempts in quick succession, however I reach the limit of synchronization and status message:
ERRORSync request rate limit exceeded.
Is there any way to increase the frequency of requests, since this is not very desirable if I should have an application offering the user "try again later to synchronize - not sure how long you will have to wait until you can though!
DECISION - VARIETIES AND MY THOUGHTS (what it costs)
The solution I'm going for (after emailing the dev application whose published application on the hard drive that syncs without problems) is to use Drive REST Api, not the newer (and preferred by Google) Drive API. I tried to limit "requestSync" only when the user navigated to the fragment with the "Disk" parameters (and not with each file transaction). However, this would probably solve the requestSync speed limit for the most part, but it could still fall within this limit. In addition, if several devices launch the application and are connected to the same Drive account, the files in the application are synchronized / uploaded / deleted, then there is the possibility of losing synchronization - perhaps a rare scenario, but still possible. I don’t feel that making the user wait to synchronize files is a viable option in terms of user interface or application design.
Curious: - The actual Drive app allows you to update (requestSync?) As many times as you like. I created 20 folders on the web interface quickly, after each folder was created, I updated the Drive app on my phone and it syncs all 20 times. Google seems to understand the importance of synchronization, but decides to make it pretty difficult for it to be in their new API. As already mentioned, uploading files to the cloud storage is usually instantaneous (it is queued, however, if you have a connection, this happens almost immediately). I would think that this is an expensive transaction in terms of moving data / updating disk contents, and not just for file synchronization requests. However, you can add files to your drive one at a time, and it downloads them one at a time almost instantly - where when you request synchronization more than 4 times in 30 seconds, and then it fails, and you need to “cool” for some time.
I am very new to programming / Android in general - as soon as I learn something new, I understand how little I know, so if this is the best solution using the Drive API (and not REST API) I really welcome it .