文件不存在仅发生在android中的XLSX文件中

时间:2014-02-26 09:33:51

标签: android

我试图在android中使用意图过滤器打开XLSX文件来选择现有的XLSX阅读器应用程序,但总是得到文件未找到异常。相同的代码适用于XLS文件。我在清单和文件路径中添加了WRITE_EXTERNAL_STORAGE权限只是正确的。文件也可在SD卡中使用。我的平板电脑有sheet to goOfficeSuite个应用程序来阅读XLSX个文件。即使我可以通过点击它打开我的XLSX文件。但尝试通过我的应用程序打开会产生问题。对于XLSX文件,我的代码总是转到else部分。提前谢谢。

private void openSpreadSheet(String fileCompletePath) {

        File file = new File(fileCompletePath);


        if (file.exists()) {
            try {
                Log.d(TAG, "File exist");
                Uri path = Uri.fromFile(file);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(path, "application/vnd.ms-excel");
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
                Toast.makeText(this,
                        "No application found to display spread sheet.",
                        Toast.LENGTH_SHORT).show();
            }
        } else {
            Log.d(TAG, "File not exist");
        }
    }

如果我删除if条件,那么意图过滤器在选择应用程序后要求选择应用程序,则所选应用程序显示此错误File not found(/Duplicate.xlsx:open failed:ENOENT(No such file or directory)).

找到解决方案     问题来了,因为我提供了错误的文件路径

0 个答案:

没有答案