exposed beyond app through ClipData.Item.getUri()


exposed beyond app through ClipData.Item.getUri()

首先AndroidManifest.xml中添加

1
2
3
4
5
6
7
8
9
<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/provider_paths" />
</provider>

res / xml / provider_paths.xml

1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path path="." name="root" />
<files-path path="files/" name="files" />
</paths>

然后修改代码

1
2
3
4
Uri u = Uri.fromFile(file);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
u = FileProvider.getUriForFile(this, this.getPackageName() + ".fileprovider", file);
}