Android 7 打开文件西里尔字母名称
Android 7 open file cyrillic name
我有一个西里尔文名称的文件:
File file = new File(cyr_name);
然后我尝试在另一个应用程序中打开它:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file ), "text/plain");
startActivity(intent);
在android版本6是没有问题的。
Android 7 是错误:
28-12 20:54:25.018 21665 21665 E AndroidRuntime: android.os.FileUriExposedException: file:///storage/emulated/0/ws/%D0%9C%D0%B5%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D0%BA%D0%B8%D0%B9_%D0%A3%D0%BD%D0%B5%D1%81%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9%20%D0%B2%D0%B5%D1%82%D1%80%D0%BE%D0%BC%20%D0%9A%D0%BD%D0%B8%D0%B3%D0%B0%20%D1%87%D0%B5%D1%82%D0%B2%D0%B5%D1%80%D1%82%D0%B0%D1%8F.txt exposed beyond app through Intent.getData()
7 android 怎么了?
它与西里尔字母无关,这是因为您使用的是无法再传递给其他应用程序的文件方案意图。您必须通过 FileProvider
传递内容意图或设置安全策略来覆盖此行为。有关使用 FileProvider
.
的示例,请参阅 https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en
如果您走那条路,这里是覆盖安全策略的方法。它设置了将文件意图公开而不是进程死亡的惩罚。在发送意图之前,您可以将它放在一些 onCreate()
中。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build();
StrictMode.setVmPolicy(policy);
}
我有一个西里尔文名称的文件:
File file = new File(cyr_name);
然后我尝试在另一个应用程序中打开它:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file ), "text/plain");
startActivity(intent);
在android版本6是没有问题的。 Android 7 是错误:
28-12 20:54:25.018 21665 21665 E AndroidRuntime: android.os.FileUriExposedException: file:///storage/emulated/0/ws/%D0%9C%D0%B5%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D0%BA%D0%B8%D0%B9_%D0%A3%D0%BD%D0%B5%D1%81%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9%20%D0%B2%D0%B5%D1%82%D1%80%D0%BE%D0%BC%20%D0%9A%D0%BD%D0%B8%D0%B3%D0%B0%20%D1%87%D0%B5%D1%82%D0%B2%D0%B5%D1%80%D1%82%D0%B0%D1%8F.txt exposed beyond app through Intent.getData()
7 android 怎么了?
它与西里尔字母无关,这是因为您使用的是无法再传递给其他应用程序的文件方案意图。您必须通过 FileProvider
传递内容意图或设置安全策略来覆盖此行为。有关使用 FileProvider
.
如果您走那条路,这里是覆盖安全策略的方法。它设置了将文件意图公开而不是进程死亡的惩罚。在发送意图之前,您可以将它放在一些 onCreate()
中。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build();
StrictMode.setVmPolicy(policy);
}