I have created an app, that creates gpx files. Everything is working fine except for the sharing. Therefore I have created a File Provider. You can see it's configuration below. The Provider is working fine on my android device running Android 8.0.0 but on a friends Huawei (6.0) it is not working
Fatal Exception: java.lang.IllegalArgumentException
Failed to find configured root that contains /storage/8737-15E4/Android/data/XXX/cache/20171009_171900.gpx
Provider in Manifest:
<provider
android:name=".GenericFileProvider"
android:authorities="com.package.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
file_paths.xml:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="external-files" path="/" />
<external-cache-path name="cache-files" path="/" />
</paths>
Usage in Code:
File gpxFile = new File(context.getExternalCacheDir(), "20171009_171900.gpx");
Uri gpxContentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", gpxFile);
Intent gpxIntent = new Intent(Intent.ACTION_SEND);
gpxIntent.setType("text/gpx");
gpxIntent.putExtra(Intent.EXTRA_STREAM, gpxContentUri);
Intent programChooser = Intent.createChooser(gpxIntent, context.getString(R.string.select_app_to_share));
programChooser.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
activityForDialog.startActivity(programChooser);
I hope someone can help me to find the bug that causes the app to crash on some devices...