【问题标题】:Open Google Drive file with new Intent使用新 Intent 打开 Google Drive 文件
【发布时间】:2015-09-22 14:43:17
【问题描述】:

我有从 Google Drive 下载的文件列表。这些文件具有不同的 mimeType,例如

"application/vnd.google-apps.folder"
"application/vnd.google-apps.file"
"application/pdf"
"video/mpeg"
"application/vnd.ms-powerpoint.presentation.macroEnabled.12"

如何以新的意图打开这些文件?

同样要打开文件,我应该使用 id(0B_uvNTGVtbi****zOS1WY78yVlU) 或标题 (RJ_****_462324_20417.pdf)

目前我正在使用,但“Android 系统已停止”:)

Intent myIntent = new Intent(Intent.ACTION_VIEW);
        myIntent.setData(Uri.parse(localFile.getTitle()));
        myIntent.setType("*/*");
        Intent intent = Intent.createChooser(myIntent, "Choose an application to open with:");
    context.startActivity(intent);

【问题讨论】:

  • 当您说“我有一个列表...”时,请指定一个列表内容(文件标题、文件 ID、...)
  • 文件和文件夹列表(不是物理文件),包含标题、id、mimetype、上次修改、已删除、已注视等所有字段。这些列表是我通过 Google Drive Api 获得的。
  • 您使用什么 API 来获取列表? GDAAREST?

标签: java android android-intent google-drive-api google-drive-android-api


【解决方案1】:

如果通过“打开”文件意味着允许用户选择他们应该打开的应用程序,则需要使用驱动器文件的 URL 并使用此 URL 发送 ACTION_VIEW 意图(有关详细信息,请参阅here) .如果用户没有安装 Drive App,该 URL 将在浏览器中打开,否则用户将获得在 DriveApp 或浏览器中打开它的选项。

【讨论】:

    【解决方案2】:

    您正在使用文件标题作为 URI,它不是有效的 URI:

    myIntent.setData(Uri.parse(localFile.getTitle()))//this is wrong
    

    您需要致电:

    myIntent.setData(Uri.fromFile(localFile))// use this instead
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多