To use Android's FileProvider to obtain the URI for a file that is located on an external SD, you will need to follow these steps:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_sd" path="."/>
</paths>
File file = new File(Environment.getExternalStorageDirectory(), "fileName.jpg");
Uri fileUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file);
Note: Replace "fileName.jpg" with the actual name of your file. Also, make sure that you have the necessary permissions to access external storage. You can use the new Storage Access Framework introduced in Android 4.4 KitKat to request permission to access external storage.
Asked: 2023-06-14 18:42:02 +0000
Seen: 11 times
Last updated: Jun 14 '23