AndroidManifest.xml在</application>标签上加入
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.myapplication.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepath" />
</provider>
在app\src\main\res\xml中加入文件filepath.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<root-path name="root" path="." />
<files-path name="files" path="." />
<external-path name="external" path="." />
<external-cache-path name="external_cache" path="." />
<external-files-path name="external_file" path="." />
</paths>