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;
}