将文件从资产文件夹复制到本地目录,并打开文件android nougat
将文件从资产文件夹复制到本地目录,打开文件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
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