【问题标题】:Android 7 open file cyrillic nameAndroid 7 打开文件西里尔文名称
【发布时间】:2016-12-29 01:49:12
【问题描述】:

我有一个西里尔文名称的文件:

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 file android-intent cyrillic


    【解决方案1】:

    这与西里尔文无关,这是因为您使用的文件方案意图不能再传递给其他应用程序。您必须使用 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2011-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多