美文网首页
Android N 的程序间资源共享问题

Android N 的程序间资源共享问题

作者: middle2021 | 来源:发表于2017-03-08 14:36 被阅读62次
1、配置Manifest文件
<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
</provider>
2、在xml目录下新建filepaths.xml文件
<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="*"
        path="/" />
</paths>
3、Uri使用
private static Uri getUriForFile(Context context, File file) {
    if (context == null || file == null) {
        throw new NullPointerException();
    }
    Uri uri;
    /**
     * Android N 用FileProvider共享数据
     */
    if (Build.VERSION.SDK_INT >= 24) {
        uri = FileProvider.getUriForFile(context.getApplicationContext(), CoreApplication.getInstance().getPackageName() + ".fileprovider", file);
    } else {
        uri = Uri.fromFile(file);
    }
    return uri;
}

相关文章

网友评论

      本文标题:Android N 的程序间资源共享问题

      本文链接:https://www.haomeiwen.com/subject/mdpbgttx.html