5

For my App I need to have a List sync with Google Drive. I have already implemented the SignIn and had my Main_Activity implement both:

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

Even though I read the whole Google Drive API for Android documentation, and more specifically the Store Application Data part. And looked through the example on GitHub, I wasn't able to get it to work. I personally think that this documentation is really confusing to read. It's not even clear what is the difference between the Google Drive API for android and the Google Drive REST API, and which one I should use for my scenario.

Also I noticed that the example on GitHub extends a custom Activity that has other methods in it.

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

Daniele
  • 4,163
  • 7
  • 44
  • 95
  • Choosing an API to use will depend on your use case. To help you with the distinction between these APIs, see this [SO post](http://stackoverflow.com/questions/42410458/difference-between-google-api-and-google-rest-api). With regards to syncing your app list with Google Drive, after you've figured out what API to use, you may want to check this [thread](https://productforums.google.com/forum/#!topic/drive/MRk_e2kUwlQ) and see if it will help you. – Teyam May 16 '17 at 10:21
  • Can you edit your post to include your MainActivity? – Sammy T May 17 '17 at 21:00

2 Answers2

3

I am familiar with your frustration. There is the "Google Drive Android API" (GDAA) and the "Drive REST API." There is some good documentation on the web, but finding it and making sense of it can be a challenge, especially since the names of the packages are so similar. In addition, there are at least two extant versions of "Drive REST API" and you have to keep the versions straight.

Regarding GDAA, you have already found this documentation, but you should take a closer look. I suggest that you do a simple activity such as creating a file and work from there.

I think that the custom Activity in the example on GitHub that you reference is the BaseDemoActivity. That class simply provides some of the life cycle methods and some other common routines.

The Google Drive Android API (GDAA) is tightly integrated with Play Services and Google claims offers better performance. (See the note here):

Note: This quickstart illustrates the use of the Drive REST API in an Android application. However, in the majority of cases production Drive apps will strongly benefit by making use of the Drive API for Android, which is integrated with Google Play Services and offers better performance. Before using the Drive REST API in your Android application, you should carefully review the Drive API for Android and use it in your application if possible. A Drive API for Android Quickstart is available if you want to learn more.

Even though, I have abandoned GDAA in most instances due to tightening restrictions on the frequency of syncing. (For more detail, see the notes at the bottom of this post.)

When working with GDAA, one key thing to keep in mind is that even though your code can run on the UI thread, GDAA cannot due to potentially lengthy tasks that it performs on your behalf. That implies that once you request GDAA to accomplish some task from the UI thread, GDAA will do that work in the background (not on the UI thread) and deliver results to you through the callbacks.

This structure, although necessary, means that your code will be a series of methods that are invoked by GDAA and will not necessarily demonstrate a clear sequential format that you may be used to. I think of it as a Pachinko machine in software.

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


Regarding Sync Frequency: More specifically, uploads to the server will occur as specified with DrivePreferencesApi. Uploads usually happens fairly quickly. Downloads, however, are rate limited. See this documentation.

In order to avoid excessive load on the device and the server, sync requests are rate limited. In this case, the operation will fail with DRIVE_RATE_LIMIT_EXCEEDED status, which indicates that a sync already happened quite recently so there is no need for another sync. The operation will succeed when reattempted after a sufficient backoff duration.

I believe that the "backoff duration" is dependent upon the version of Play Services installed. In my experience, this duration varied from a couple of minutes to 1/2 hour or more. This may have changed and I tried to find documentation on this but was unsuccessful.

If the download limitation of GDAA doesn't work for you, then you may want to consider Drive REST. You can also look into Firebase as a possible solution.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • Thanks for the answer, It definitely helped a lot, what are exactly the restrictions on the syncing frequency you are talking about. This could be kinda crucial for me. – Daniele May 24 '17 at 09:33
  • am having one doubt can i access file from another account using drivid using native api in android becuase i have successfully completed the upload and download the file using the same account but while using other account am getting authorization exception is it possible to do so using rest api – M.Yogeshwaran Apr 19 '18 at 06:24
  • The Android Drive API only works with the https://www.googleapis.com/auth/drive.file scope. This means that only files which a user has opened or created with your application can be matched by a query. – DKV Dec 11 '18 at 12:18
0

Google Drive Android API illustrates all possible ways to talk to Drive service with the use of interfaces available in Google Play Services. Check this URI for the quick start. https://github.com/googledrive/android-demos

Google Drive REST API will be useful for all the technologies not only for android. as shown in the Google Drive REST API Documentation

Ramana V V K
  • 1,245
  • 15
  • 24