I have written an Android app with AndroidStudio, which create configuration files in JSON format, which are saved on device and can be shared.
Before Android 12 this worked without any problems. With Android 12 I got problems with saving the files but shareing still worked. I was able to fix saving by using a subdirectory at Documents instead of app's directory. Fixed saving works also on Android 13. But on Android 13 sharing via Outlook does no longer work (Unable to add attachment). With Teams it still can be shared.
The files are shared with this code:
//File file is selected by user
Uri path = Uri.fromFile(file);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("vnd.android.cursor.dir/email"); //I tried it also with "*/*"
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
startActivity(Intent.createChooser(emailIntent , "Share..."));
Does anyone know a reason why shareing via Outlook does no longer work or does anyone know an example app, which is able to share self created and saved JSON files on Android 13?
After first response I defined a FileProvider in AndroidManifest.xml:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.test.project.fileProvider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_path"/>
</provider>
Additionally, I added file_provider_path.xml to res/xml with following content:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path
name="external_files"
path="."/>
</paths>
And I changed code for getting Uri to
File file = new File(getCacheDir(), "testfile.json");
//... content is written with BufferedWriter
Uri path = FileProvider.getUriForFile(this,"com.test.example.fileProvider", file);
//Uri then is content://com.test.project.fileProvider/external_files/testfile.json
Thank you for any help and kind regards, Wolfgang
Finally I created a very example Android app, which creates a file and implements sharing this file with FileProvider: SharingTestApp I hope this example helps others to implement file sharing 🙂