TL / DR:如何从后台运行的服务访问Google服务?
有两个版本连接到Drive API
他们都没有告诉如何在后台服务中使用它,例如偶尔保存用户数据。
另外在另一个android guide我发现使用GoogleAuthUtil
可以帮助我获取以后可以使用的令牌,但是我找不到关于如何通过令牌使用Drive API的单个示例!
答案 0 :(得分:0)
关于保存文件到Google云端硬盘的示例代码,您可以参考此链接(https://github.com/googledrive/android-demos/blob/master/app/src/main/java/com/google/android/gms/drive/sample/demo/EditContentsActivity.java).But,此示例使用AsyncTask而非Service作为后台进程。 如果真的想在Service中实现该过程,可以通过将EditContentsAsyncTask的代码复制粘贴到Service来实现。 在示例代码中不使用服务的原因是因为Service默认情况下仍然在应用程序的主线程中运行, 关于Service和AsyncTask,您可以参考此链接“您是否应该使用服务或线程?”(http://developer.android.com/guide/components/services.html)。
使用GoogleAuthUtil和GoogleApiClient之间的区别,您可以参考此链接(what is the right way to sign in google: GoogleAuthUtil or GoogleApiClient)。