Skip to content

Instantly share code, notes, and snippets.

@s1ntoneli
Last active November 19, 2017 08:38
Show Gist options
  • Select an option

  • Save s1ntoneli/fc8e779cae4ec4021e2f7524292a4205 to your computer and use it in GitHub Desktop.

Select an option

Save s1ntoneli/fc8e779cae4ec4021e2f7524292a4205 to your computer and use it in GitHub Desktop.
android N 图片分享问题

android N 开始不允许以 file:// 的方式通过 Intent 在两个 App 之间分享文件,取而代之的是通过 FileProvider 生成 content://Uri

这要求分享文件的两个 App 都需要支持这种新的 schema, 而事实并非如此。大量的第三方应用还并未支持这种新的文件共享方式。巨头应用微博就是其中之一。

为了更好的适配这些第三方应用,可以使用下面两种解决方式:

  1. 更改 targetSdkVersion 到 24 以下

  2. StrictMode 不设置 detectFileUriExposure

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment