1 year ago
#326230
GoshkaLP
Sharing images with FileProvider doesn't work correctly
I am new to android development and I ran into problems sending files via FileProvider.
I am trying to send file from storage
to other Apps on device. But unfortunately the file can't be attached in all apps.
Here is my AndroidManifest.xml
<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/provider_paths"/>
</provider>
provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="download" path="Download" />
</paths>
MainActivity.java
Intent shareIntent = new Intent();
String filename = "cat.jpg";
String fullPath = Environment.getExternalStorageDirectory() + "/Download/" + filename;
File file = new File(fullPath);
Uri uriToImage = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivity(shareIntent);
This example works when I am sharing file from app's external storage, but I want to send the file from the internal storage of the device. Where could I go wrong?
java
android
android-fileprovider
0 Answers
Your Answer