Android - using the Google Drive API for Android

For my application, I need to sync List with Google Drive. I have already implemented SignIn and used my Main_Activity tool:

com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks,
com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener

      

Even though I have read all the documentation of Google Drive API for Android , or rather Store Application Data . And looked at an example on GitHub , I couldn't get it to work. I personally find this documentation really confusing to read. It's not even clear what is the difference between the Google Drive Android API and the Google Drive REST API, and which one should I use for my scenario.

Also I noticed that the example on GitHub extends the user activity that has other methods.

Can any of you explain step by step how to use the Android API?

+3


source to share


2 answers


I am familiar with your disappointment. There is a "Google Android Android API" (GDAA) and a "Drive REST API". There is good documentation on the internet, but finding it and understanding it can be a challenge, especially since the package names are so similar. In addition, there are at least two existing versions of the "Drive REST API", and you must keep the versions strictly consistent.

As far as the GDAA is concerned, you've already found this documentation , but you should take a closer look at it. I suggest you do a simple activity like create a file and work from there.

I think the custom Activity in the example on GitHub you specify is BaseDemoActivity

. This class just provides some of the lifecycle methods and some other common routines.

The Google Drive Android API (GDAA) is tightly integrated with Play Services, and Google's requirements offer better performance. (See note here ):

Note. This quick start illustrates using the REST Drive API in an Android app. However, in most cases, Drive Drive applications will greatly benefit from using the Android Drive API, which is integrated with Google Play services and provides better performance. Before using the REST REST API in an Android app, you should take a close look at the Android Drive API and use it in your app, if possible. The Drive API for Android Quickstart is available if you'd like to learn more.

Despite the fact that I have given up on GDAA in most cases due to tightening restrictions on the frequency of synchronization. (See the notes at the bottom of this post for more details.)

When working with GDAA, keep in mind that even though your code can run on the UI thread, GDAA cannot because of the potentially time-consuming tasks it performs on your behalf. This means that after you ask GDAA to do some task from the UI thread, GDAA will do that work in the background (not on the UI thread) and deliver the results to you via callbacks.



This structure, while necessary, means that your code will be a series of methods that are called by GDAA and will not necessarily exhibit a clear sequential format that you might get used to. I think of it as a Pachinko machine in software.

While this is not a step-by-step set of instructions, I hope this helps you in the right direction.


As for the sync frequency: More specifically, the upload to the server will be done according to DrivePreferencesApi

. Loading is usually pretty fast. Downloads, however, are speed limited. See this documentation .

To avoid overloading the device and server, sync requests are rate limited. In this case, the operation will fail with a DRIVE_RATE_LIMIT_EXCEEDED status, indicating that the synchronization has already occurred quite recently, so there is no need for another synchronization. The operation will be successful if you try again after a sufficient grace period.

I believe the "grace period" depends on the version of the Play Service installed. In my experience, this duration ranged from a couple of minutes to an hour and a half or more. This may have changed and I tried to find some documentation on the matter but failed.

If GDAA load limiting doesn't work for you, you might want to consider Drive REST. You can also look at Firebase for a possible solution.

+2


source


Google Android The Android API demonstrates every possible way to communicate with the Drive service using the interfaces available on Google Play services. Check this URI for a quick start. https://github.com/googledrive/android-demos



The Google Drive REST API will be useful for all technologies, not just Android. as shown in Google REST API Documentation

0


source







All Articles