FileProvider
step 1: create java- file and extendsits withFileProvider
public class MyFileProvider extends FileProvider {
}
step 2: create a resource file xmldirectory res/xml/and copy this code into it
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
step 3: in your file manifestunder <Application>add this code
<provider
android:name="MyFileProvider" <!-- java file created above -->
android:authorities="${applicationId}.MyFileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
Step 4: use this code to get Urito the content://format
Uri uri = FileProvider.getUriForFile(CameraActivity.this, "your.package.name.MyFileProvider", file );
Note: you may need to add read permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
source
share