使用 Google 驱动器 Android API 从 Google 驱动器下载图像?

Downloading Images from Google Drive using Google Drive Android API?

基本上,我一直在使用这个指南:https://developers.google.com/drive/android/intro

在以下帮助下,我已将图片上传到驱动器中:https://github.com/googledrive/android-demos/tree/master/src/com/google/android/gms/drive/sample/demo

但是,上面链接的 GitHub 项目不提供任何从云端硬盘检索图像的方法,它只显示文本文件。我知道 QueryNonTextFilesActivity.java 但这会在附加到 ResultsAdapter 的 MetaDataBuffer 中给出结果。我的问题是:如何使用这些数据并将其转换为图像 (.png)?

谢谢

假设您有 DriveId from when you inserted the image, you can then retrieve the file using Drive.DriveApi.getFile() - this returns you a DriveFile.

一旦有了 DriveFile,就可以使用 open() 和代码

将文件内容作为位图 InputStream
file.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null)
    .setResultCallback(
      new ResultCallback<DriveApi.DriveContentsResult>() {
        @Override
        public void onResult(DriveApi.DriveContentsResult result) {
        if (!result.getStatus().isSuccess()) {
          // Handle an error
        }
        DriveContents driveContents = result.getDriveContents();
        InputStream is = driveContents.getInputStream();
        Bitmap bitmap = BitmapFactory.decodeStream(is);
        // Do something with the bitmap

        // Don't forget to close the InputStream
        is.close();
      });