【问题标题】:Unable to read file from App folder of Google Drive无法从 Google Drive 的 App 文件夹中读取文件
【发布时间】:2015-05-16 07:57:14
【问题描述】:

我在 Google Drive 的 App 文件夹中创建了一个文件。

写入文件的代码

OutputStream outputStream = result.getDriveContents().getOutputStream();
try { 
        outputStream.write(text.toString().getBytes()); 
} catch (IOException e1) { 
        Log.i(TAG, "Unable to write file contents."); 
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                    .setTitle("appconfig.txt")
                    .setMimeType("text/plain")
                    .build();
Drive.DriveApi.getAppFolder(getGoogleApiClient())
                    .createFile(getGoogleApiClient(),changeSet,result.getDriveContents())
                    .setResultCallback(fileCallback);

这已成功写入 App 文件夹。现在我必须读取写入的文件。

读取文件的代码

DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient, driveId);
DriveContentsResult driveContentsResult = file.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).await();

System.out.println("result success "+driveContentsResult.getStatus().isSuccess());

driveContentsResult 的状态为 false。 我看过谷歌的演示,但找不到解决方案。谁能帮我找出我犯了什么错误或我可以尝试的其他方法。

【问题讨论】:

  • 我们的 logcat 有什么值得注意的地方吗?

标签: android google-drive-android-api


【解决方案1】:

如果您提供更多信息会有所帮助,但您可以尝试以下几点:

  1. 结帐https://github.com/googledrive/android-demos/blob/master/src/com/google/android/gms/drive/sample/demo/CreateFileInAppFolderActivity.java

  2. 查看结果中的错误信息:driveContentsResult.getStatus().getStatusMessage()

  3. 在 logcat 中查找任何相关的日志输出

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    相关资源
    最近更新 更多