flutter_share icon indicating copy to clipboard operation
flutter_share copied to clipboard

PlatformException(Failed to find configured root that contains /file:/storage/emulated/0/project/1590844068701.png, null, null)

Open kashifg4171 opened this issue 5 years ago • 11 comments

PlatformException(Failed to find configured root that contains /file:/storage/emulated/0/project/1590844068701.png, null, null)

I'm facing this exception while sharing image file. I had added path provider code in AndroidMinifest.xml file, make new file provider_path.xml in src/xml/...

Any solution please.

kashifg4171 avatar May 30 '20 13:05 kashifg4171

The only way i fixed it is by making sure im saving the image to the Cache directory (with path_provider plugin) calling getExternalStorageDirectory then setting the following in my xml file (covering all bases)

<external-path name="external" path="." />
<external-files-path name="external_files" path="." />
<cache-path name="cache" path="." />
<external-cache-path name="external_cache" path="." />
<files-path name="files" path="." />

marcLeeroy avatar Jun 03 '20 12:06 marcLeeroy

The only i fixed it is by making sure im saving the image to the Cache directory (with path_provider plugin) calling getExternalStorageDirectory then setting the following in my xml file (covering all bases)

<external-path name="external" path="." />
<external-files-path name="external_files" path="." />
<cache-path name="cache" path="." />
<external-cache-path name="external_cache" path="." />
<files-path name="files" path="." />

can you please explain where exactly you called getExternalStorageDirectory ?

00AhmedMokhtar00 avatar Jun 04 '20 21:06 00AhmedMokhtar00

In my case i call before i save an image to disk (build my path with it as a save location). In your case you might be loading a file to share.

marcLeeroy avatar Jun 05 '20 00:06 marcLeeroy

One thing to note is that you need to pass the absolute file path to shareFile. This tripped me up for a while.

iwishiwasaneagle avatar Jun 15 '20 16:06 iwishiwasaneagle

I'm trying to share a file from AppData using this. It works fine on iOS but gives this error when sharing on Android. Any idea how to share files from AppData?

anshgwash avatar Jul 26 '20 15:07 anshgwash

Another way to handle this would be to save your file in the getExternalStorageDirectory before sharing and pass the absolute path of that. Haven't tried it, but will post back the results.

If anyone has a work around for this please share.

ghost avatar Aug 13 '20 21:08 ghost

I have a work around of this nature. see issue #27 for details.

skionthursday avatar Aug 16 '20 04:08 skionthursday

Had the same problem, this did the trick for me for iOS and Android devices. Thanks @bretie for the suggestion

  var output;

  if (Platform.isIOS) {
    output = await getTemporaryDirectory();
  } else {
    output = await getExternalStorageDirectory();
  }
  final file = File("${output.path}/doc.pdf");
  await file.writeAsBytes(<Uint8List> file);

  try {
    await FlutterShare.shareFile(
      title: "Title",
      filePath: file.path,
    );
  } catch (err) {
    print(err);
  }

rihardsba avatar Aug 20 '20 12:08 rihardsba

getExternalStorageDirectory

can't call getExternalStorageDirectory, can you please explain where did you called that function

muhd-ameen avatar Apr 18 '22 18:04 muhd-ameen

On Android (happily avoid platform specific handlings) I can use tmpDir = await getTemporaryDirectory() and File('${tmpDir.path}/kapitel.json') as well with only this rule <cache-path name="cache" path="." /> The share dialogue opens and the file sharing works, despite the error log messages:

Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://de.someapp.provider/cache/kapitel.json from pid=20044, uid=1000 requires the provider be exported, or grantUriPermission()

0llie avatar Nov 14 '22 10:11 0llie

On Android (happily avoid platform specific handlings) I can use tmpDir = await getTemporaryDirectory() and File('${tmpDir.path}/kapitel.json') as well with only this rule <cache-path name="cache" path="." /> The share dialogue opens and the file sharing works, despite the error log messages:

Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://de.someapp.provider/cache/kapitel.json from pid=20044, uid=1000 requires the provider be exported, or grantUriPermission()

I have the same case, but the log with the exception seems to be a problem to me

ron-diesel avatar Jan 28 '23 13:01 ron-diesel