如何打开具有给定存储路径的任何格式的文件
How to open file of any format with given storage path
我只想从我的内部或外部存储打开文件,给定路径如 /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"));
但它不起作用..请提供工作代码。
请确保您的设备中至少有一个应用程序可以读取您的文件格式。
另外,请使用此意图:Intent(android.content.Intent.ACTION_VIEW) 而不是您的意图。
我只想从我的内部或外部存储打开文件,给定路径如 /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"));
但它不起作用..请提供工作代码。
请确保您的设备中至少有一个应用程序可以读取您的文件格式。 另外,请使用此意图:Intent(android.content.Intent.ACTION_VIEW) 而不是您的意图。