使用新的Intent打开Goog​​le云端硬盘文件

时间:2015-09-22 14:43:17

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

我有从Google云端硬盘下载的文件列表。这些文件具有不同的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)或title(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);

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

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

您需要致电:

myIntent.setData(Uri.fromFile(localFile))// use this instead
相关问题