gpt4 book ai didi

android - 断开应用后 Google Drive Android API 仍然返回成功结果,但不上传文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:25:56 29 4
gpt4 key购买 nike

我正在使用 Google Drive Android API(作为 Google Play 服务的一部分)将文件上传到云端。

要连接客户端,我使用以下代码(已简化):

apiClient = new GoogleApiClient.Builder(context)
.addApi(Drive.API)
.setAccountName(preferences.getString("GOOGLE_DRIVE_ACCOUNT", null))
.build();

ConnectionResult connectionResult = apiClient.blockingConnect(SERVICES_CONNECTION_TIMEOUT_SEC, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
throw new ApiConnectionException(); //our own exception
}

要上传文件,我使用以下代码(简化):

DriveApi.ContentsResult result = Drive.DriveApi.newContents(apiClient).await();
if (!result.getStatus().isSuccess()) {
/* ... code for error handling ... */
return;
}

OutputStream output = result.getContents().getOutputStream();
/* ... writing to output ... */

//create actual file on Google Drive
DriveFolder.DriveFileResult driveFileResult = Drive.DriveApi
.getFolder(apiClient, folderId)
.createFile(apiClient, metadataChangeSet, result.getContents())
.await();

除了一个特定的用户案异常(exception),一切都按预期工作。当用户从“连接的应用程序”(使用 Google 设置应用程序)中删除我们的应用程序时,此代码仍会为所有调用返回成功的结果。尽管文件从未上传到 Google 云端硬盘。

与 Google Play 服务的连接也成功。

这是 API 的错误还是可以以某种方式检测到用户断开了应用程序?

最佳答案

我不知道 API 的内部/外部,但是此页面可能会有所帮助 https://support.google.com/drive/answer/2523073?hl=en .我会仔细检查 accounts.google.com 页面并确认所有权限都已被删除。这不会解决 api 行为,但至少您可以验证权限。

关于android - 断开应用后 Google Drive Android API 仍然返回成功结果,但不上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24011801/

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