gpt4 book ai didi

Android - 使用适用于 Android 的 Google Drive API

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:20 25 4
gpt4 key购买 nike

对于我的应用程序,我需要将列表与 Google 云端硬盘同步。我已经实现了 SignIn 并让我的 Main_Activity 实现了这两个:

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

尽管我阅读了整个Google Drive API for Android文档,更具体地说是 Store Application Data部分。并查看了 example on GitHub ,我无法让它工作。我个人认为这份文档读起来真的很困惑。甚至不清楚适用于 Android 的 Google Drive API 和 Google Drive REST API 之间的区别是什么,以及我应该在我的场景中使用哪一个。

我还注意到 GitHub 上的示例扩展了一个自定义 Activity ,其中包含其他方法。

谁能一步步解释如何使用 android 驱动器 API?

最佳答案

我很了解你的沮丧。有“Google Drive Android API”(GDAA) 和“Drive REST API”。网络上有一些很好的文档,但找到它并理解它可能是一个挑战,尤其是因为包的名称非常相似。此外,“Drive REST API”至少有两个现存版本,您必须保持版本正确。

关于GDAA,你已经找到了这个documentation , 但你应该仔细看看。我建议你做一个简单的 Activity ,比如 creating a file并从那里开始工作。

我认为您引用的 GitHub 示例中的自定义 Activity 是 BaseDemoActivity。该类只是提供了一些生命周期方法和一些其他常用例程。

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。 (有关更多详细信息,请参阅本文底部的注释。)

使用 GDAA 时,要牢记的一件关键事情是,即使您的代码可以在 UI 线程上运行,GDAA 也不能,因为它代表您执行的任务可能很长。这意味着一旦您请求 GDAA 从 UI 线程完成某些任务,GDAA 将在后台(而不是在 UI 线程上)完成该工作并通过回调将结果传递给您。

这种结构虽然是必要的,但意味着您的代码将是一系列由 GDAA 调用的方法,并且不一定会展示您可能习惯的清晰的顺序格式。我将其视为软件中的弹球机。

虽然这不是一套循序渐进的说明,但我希望这能帮助您指明正确的方向。


关于同步频率:更具体地说,将按照 DrivePreferencesApi 指定的方式上传到服务器。 .上传通常发生得相当快。但是,下载是有速率限制的。参见 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.

我认为“退避持续时间”取决于安装的 Play 服务版本。根据我的经验,这个持续时间从几分钟到 1/2 小时或更长时间不等。这可能已经改变,我试图找到这方面的文档,但没有成功。

如果 GDAA 的下载限制对您不起作用,那么您可能需要考虑 Drive REST。您还可以将 Firebase 视为可能的解决方案。

关于Android - 使用适用于 Android 的 Google Drive API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43981182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com