Android - 使用 Google 驱动器 API 用于 android
Android - Using the Google Drive API for android
对于我的应用程序,我需要将列表与 Google Drive 同步。我已经实现了 SignIn 并让我的 Main_Activity 实现了:
com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks,
com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener
尽管我通读了整个 Google Drive API for Android documentation, and more specifically the Store Application Data part. And looked through the example on GitHub,但我还是无法让它发挥作用。我个人认为这份文档读起来真的很混乱。甚至不清楚 Google Drive API for android 和 Google Drive REST API 之间的区别是什么,我应该使用哪一个情景.
我还注意到 GitHub 上的示例扩展了一个包含其他方法的自定义 Activity。
谁能一步步解释如何使用 android 驱动器 API?
Google Drive Android API 说明了使用 Google Play 服务中可用的接口与 Drive 服务对话的所有可能方式。
检查此 URI 以快速启动。
https://github.com/googledrive/android-demos
Google Drive REST API 将对所有技术都有用,而不仅仅是 android。如Google Drive REST API Documentation
所示
我很了解你的沮丧。有 "Google Drive Android API" (GDAA) 和 "Drive REST API." 网络上有一些很好的文档,但是找到它并理解它可能是一个挑战,尤其是因为包的名称非常相似.此外,"Drive REST API" 至少有两个现存版本,您必须保持版本正确。
关于 GDAA,您已经找到了这个 documentation, but you should take a closer look. I suggest that you do a simple activity such as creating a file 并从那里开始工作。
我认为您引用的 GitHub 示例中的自定义 Activity 是 BaseDemoActivity
。那class只是提供了一些生命周期的方法和一些其他的常用例程。
Google Drive Android API (GDAA) 与 Play 服务紧密集成,Google 声称可提供更好的性能。 (见注释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.
尽管如此,由于对同步频率的严格限制,我在大多数情况下都放弃了 GDAA。 (有关详细信息,请参阅此 post 底部的注释。)
使用 GDAA 时,要牢记的一件关键事情是,即使您的代码可以 运行 在 UI 线程上,GDAA 也不能,因为它可能会在您的线程上执行冗长的任务代表。这意味着一旦您请求 GDAA 从 UI 线程完成某些任务,GDAA 将在后台完成该工作(而不是在 UI 线程上)并通过回调将结果传递给您。
这种结构虽然是必要的,但意味着您的代码将是一系列由 GDAA 调用的方法,不一定会展示您可能习惯的清晰的顺序格式。我认为它是软件中的弹珠机
虽然不是一套循序渐进的说明,但我希望这能帮助您指明正确的方向。
关于同步频率:
更具体地说,上传到服务器将按照 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.
我认为 "backoff duration" 取决于安装的 Play 服务版本。根据我的经验,这个持续时间从几分钟到 1/2 小时或更长时间不等。这可能已经改变,我试图找到这方面的文档,但没有成功。
如果 GDAA 的下载限制对您不起作用,那么您可能需要考虑 Drive REST。您还可以将 Firebase 视为可能的解决方案。
对于我的应用程序,我需要将列表与 Google Drive 同步。我已经实现了 SignIn 并让我的 Main_Activity 实现了:
com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks,
com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener
尽管我通读了整个 Google Drive API for Android documentation, and more specifically the Store Application Data part. And looked through the example on GitHub,但我还是无法让它发挥作用。我个人认为这份文档读起来真的很混乱。甚至不清楚 Google Drive API for android 和 Google Drive REST API 之间的区别是什么,我应该使用哪一个情景.
我还注意到 GitHub 上的示例扩展了一个包含其他方法的自定义 Activity。
谁能一步步解释如何使用 android 驱动器 API?
Google Drive Android API 说明了使用 Google Play 服务中可用的接口与 Drive 服务对话的所有可能方式。 检查此 URI 以快速启动。 https://github.com/googledrive/android-demos
Google Drive REST API 将对所有技术都有用,而不仅仅是 android。如Google Drive REST API Documentation
所示我很了解你的沮丧。有 "Google Drive Android API" (GDAA) 和 "Drive REST API." 网络上有一些很好的文档,但是找到它并理解它可能是一个挑战,尤其是因为包的名称非常相似.此外,"Drive REST API" 至少有两个现存版本,您必须保持版本正确。
关于 GDAA,您已经找到了这个 documentation, but you should take a closer look. I suggest that you do a simple activity such as creating a file 并从那里开始工作。
我认为您引用的 GitHub 示例中的自定义 Activity 是 BaseDemoActivity
。那class只是提供了一些生命周期的方法和一些其他的常用例程。
Google Drive Android API (GDAA) 与 Play 服务紧密集成,Google 声称可提供更好的性能。 (见注释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.
尽管如此,由于对同步频率的严格限制,我在大多数情况下都放弃了 GDAA。 (有关详细信息,请参阅此 post 底部的注释。)
使用 GDAA 时,要牢记的一件关键事情是,即使您的代码可以 运行 在 UI 线程上,GDAA 也不能,因为它可能会在您的线程上执行冗长的任务代表。这意味着一旦您请求 GDAA 从 UI 线程完成某些任务,GDAA 将在后台完成该工作(而不是在 UI 线程上)并通过回调将结果传递给您。
这种结构虽然是必要的,但意味着您的代码将是一系列由 GDAA 调用的方法,不一定会展示您可能习惯的清晰的顺序格式。我认为它是软件中的弹珠机
虽然不是一套循序渐进的说明,但我希望这能帮助您指明正确的方向。
关于同步频率:
更具体地说,上传到服务器将按照 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.
我认为 "backoff duration" 取决于安装的 Play 服务版本。根据我的经验,这个持续时间从几分钟到 1/2 小时或更长时间不等。这可能已经改变,我试图找到这方面的文档,但没有成功。
如果 GDAA 的下载限制对您不起作用,那么您可能需要考虑 Drive REST。您还可以将 Firebase 视为可能的解决方案。