android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()在应用程序之外公开
问题: The app is crashing when I'm trying to open a file. 当我尝试打开文件时,应用程序崩溃。 It works below Android Nougat, but on Android Nougat it crashes. 它在Android Nougat以下运行,但是在Android Nougat上崩溃。 It only crashes when I try to open a file from the SD card, not from the system partition. 仅当我尝试从SD卡而不是系统分区打开文件时,它才会崩溃。 Some permission problem? 一些权限问题? Sample code: 样例代码: File file = new File("/storage/emulated/0/test.txt"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "text/*"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); // Crashes on this