寻找将课程资料下载到 android 手机的方法

Finding a way to download course materials to android mobile

有什么方法可以将 google 驱动文件下载到自定义位置吗?我正在使用此代码获取文件,

courses.get(0).getCourseMaterialSets().get(0).getMaterials().get(0).getDriveFile()

此函数正在返回文件类型输出。如何保存到本地?

或者有什么方法可以使用课堂 google 下载驱动文件 API?

我认为没有办法使用 Classroom API 来做到这一点。要从 Google 驱动器下载文件,请使用 Android API for Drive 查看下载文件教程。

Downloading a file

Preferred method: using alt=media

To download files, you make an authorized HTTP GET request to the file's resource URL and include the query parameter alt=media. For example:

GET https://www.googleapis.com/drive/v2/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media

Authorization: Bearer ya29.AHESVbXTUv5mHMo3RYfmS1YJonjzzdTOFZwvyOAUVhrs Downloading the file requires the user to have at least read access. Additionally, your app must be authorized with a scope that allows reading of file content. For example, an app using the drive.readonly.metadata scope would not be authorized to download the file contents. Users with edit permission may restrict downloading by read-only users by setting the restricted label to true.

这是指南中的一个片段:

/**
   * Download a file's content.
   *
   * @param service Drive API service instance.
   * @param file Drive File instance.
   * @return InputStream containing the file's content if successful,
   *         {@code null} otherwise.
   */
  private static InputStream downloadFile(Drive service, File file) {
    if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
      try {
        // uses alt=media query parameter to request content
        return service.files().get(file.getId()).executeMediaAsInputStream();
      } catch (IOException e) {
        // An error occurred.
        e.printStackTrace();
        return null;
      }
    } else {
      // The file doesn't have any content stored on Drive.
      return null;
    }
  }