如何使用给定的存储路径打开任何格式的文件

时间:2017-06-04 06:47:34

标签: android android-intent android-file

我只想打开来自我的内部或外部存储的文件,其中包含 /storage/emulated/0/46_1244625499.gif 这样的路径,不仅仅是图像,还可以是.pdf之类的任何格式。我只想在按钮点击事件上执行此操作,该事件为我提供了各种打开选项以打开该文件。

我试着跟随:

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
 Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+ filename); //filename is string with value 46_1244625499.gif
                intent.setDataAndType(uri, "text/csv");
                startActivity(Intent.createChooser(intent, "Open folder"));

但它不起作用..请提供工作代码。

1 个答案:

答案 0 :(得分:0)

请确保您的设备中至少有一个可以读取文件格式的应用程序。 另外,请使用以下意图: Intent(android.content.Intent.ACTION_VIEW)代替您的意图。