Android7.0android.os.FileUriExposedException: file:///storage/emulated/0/through Intent.getData()

关于android 7.0 错误 Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/c90d0cf8b0.dwg exposed beyond app through Intent.getData()

错误代码 :`

                     Intent intent = new Intent("android.intent.action.VIEW");
                     intent.addCategory("android.intent.category.DEFAULT");
                     intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setDataAndType (Uri.fromFile(file), "application/pdf");
                     startActivity(intent);`

解决方案: 把最后一行 startActivity(intent) 修改成 startActivity(Intent.createChooser(intent, “标题”));

解决之后的代码:`

                Intent intent = new Intent("android.intent.action.VIEW");
                intent.addCategory("android.intent.category.DEFAULT");
                intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setDataAndType (Uri.fromFile(file), "application/pdf");
//              startActivity(intent);
                startActivity(Intent.createChooser(intent, "标题"));`

你可能感兴趣的:(Android)