使用新的意图打开Goog le云端硬盘文件

问题描述 投票:0回答:2

我有从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)或标题(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);
java android android-intent google-drive-api google-drive-android-api
2个回答
0
投票

[如果通过“打开”文件,您是要允许用户选择应在其中打开应用的应用程序,您需要使用驱动器文件的URL并使用该URL发送ACTION_VIEW意图(有关详细信息,请参见here)。如果用户未安装Drive App,则该URL将在浏览器中打开,否则用户可以选择在DriveApp或浏览器中将其打开。


0
投票

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

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

您需要致电:

myIntent.setData(Uri.fromFile(localFile))// use this instead
© www.soinside.com 2019 - 2024. All rights reserved.