Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将文件从资产文件夹复制到本地目录,并打开文件android nougat_Android_Android 7.0 Nougat - Fatal编程技术网

将文件从资产文件夹复制到本地目录,并打开文件android nougat

将文件从资产文件夹复制到本地目录,并打开文件android nougat,android,android-7.0-nougat,Android,Android 7.0 Nougat,将文件从资产文件夹复制到本地目录,打开文件android nougat未打开 下面是复制文件然后打开它的代码 public void openSample(Context context) { try { copyFile(context.getAssets().open("sample.xlsx"), new FileOutputStream(new File(Environment.getExternalStorageDirectory() , "Do

将文件从资产文件夹复制到本地目录,打开文件android nougat未打开

下面是复制文件然后打开它的代码

public void openSample(Context context) {
        try {
            copyFile(context.getAssets().open("sample.xlsx"), new FileOutputStream(new File(Environment.getExternalStorageDirectory() , "Download/sample.xlsx")));
            File excelFile = new File(Environment.getExternalStorageDirectory() , "Download/sample.xlsx");
            Uri path = null;
            Intent intent = null;
            intent = new Intent(Intent.ACTION_VIEW);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                path = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", excelFile);

                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {
                path = Uri.fromFile(excelFile);
            }
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setDataAndType(path, "application/vnd.ms-excel");
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void copyFile(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        if (out != null) {
            out.close();
        }
    }
查找下面的附件,查看打开文件时出现的错误


提前谢谢。

在棉花糖中测试怎么样它有效吗???
android nougat没有打开
??安德鲁特牛轧糖?Android Nougat不会尝试打开文件。Android根本不会打开文件。文件由专门的应用程序打开。是哪个应用程序显示了这条消息?@Roy它在棉花糖中运行良好。在Microsoft Excel中显示了这条消息@格林纳普斯汉克斯。。U2@Roy