lubritto / flutter_share

A Flutter plugin for IOS and Android providing a simple way to share a message, link or local files.
MIT License
42 stars 50 forks source link

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

Open kashifg4171 opened 4 years ago

kashifg4171 commented 4 years ago

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.

marcLeeroy commented 4 years ago

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="." />
00AhmedMokhtar00 commented 4 years ago

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 ?

marcLeeroy commented 4 years ago

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.

iwishiwasaneagle commented 4 years ago

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

anshgwash commented 4 years ago

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?

ghost commented 4 years ago

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.

skionthursday commented 4 years ago

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

rihardsba commented 4 years ago

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);
  }
muhd-ameen commented 2 years ago

getExternalStorageDirectory

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

0llie commented 1 year ago

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()
ron-diesel commented 1 year ago

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