我不确定到底是什么导致了这个问题,但是,我怀疑我可能是把文件路径弄错了。我更改了一些内容(包括excel文件的保存位置)。更改自
/storage/emulated/0/
/storage/emulated/0/Samsung
)以下是有效的方法:
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File("/storage/emulated/0/Samsung"+File.separator + race.getName()+".xls");
Uri path = FileProvider.getUriForFile(getApplicationContext(), "com.something.racecalculator.fileprovider", file);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(path, "application/vnd.ms-excel");
startActivity(intent);
请记住,您需要实现一个
FileProvider
如果您的目标SDK为24或以上