open_file: Failed to find configured root that contains ...

used version: 3.3.2 flutter version: 3.10.4 anodrid 12

I cannot open my image with open_file. The app has permission (permission_handler) and I added everything to Manifest.xml. The interesting thing is that I define a different path to the file than specified in the exception. I’m using ‘/data/user/0/xxx/images/1.jpg’

Seems to be the same issue as https://github.com/crazecoder/open_file/issues/94

E/MethodChannel#open_file(13238): Failed to handle method call
E/MethodChannel#open_file(13238): java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/xxx/images/1.jpg
E/MethodChannel#open_file(13238): 	at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:825)
E/MethodChannel#open_file(13238): 	at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:450)
E/MethodChannel#open_file(13238): 	at com.crazecoder.openfile.OpenFilePlugin.startActivity(OpenFilePlugin.java:170)
E/MethodChannel#open_file(13238): 	at com.crazecoder.openfile.OpenFilePlugin.onMethodCall(OpenFilePlugin.java:109)
E/MethodChannel#open_file(13238): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#open_file(13238): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#open_file(13238): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#open_file(13238): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#open_file(13238): 	at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#open_file(13238): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#open_file(13238): 	at android.os.Looper.loop(Looper.java:223)
E/MethodChannel#open_file(13238): 	at android.app.ActivityThread.main(ActivityThread.java:7656)
E/MethodChannel#open_file(13238): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#open_file(13238): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#open_file(13238): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

I used this filepaths.xml:

<?xml version="1.0" encoding="utf-8"?> <resources> <external-path name="external_storage_directory" path="." /> </resources>

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

I don’t know why, but when I add the code as below, it works fine.

Hope you can help me in any way.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <root-path name="root" path="."/> <-- added
    <external-files-path name="external_storage_directory" path="." />
</resources>

I tried it in the example, and it didn’t report an error, it just couldn’t find the file

but the file is definitely there, I checked it via device explorer

I’m also having this issue.

The requested directory looks like this:

/data/user/0/com.example.app/app_flutter/files/my_folder/my_file.jpg

I am using path_provider getApplicationDocumentsDirectory to achieve this.

But when using OpenFile, it attempts a directory that looks like this:

/data/data/com.example.app/app_flutter/files/my_folder/my_file.jpg

Is this correct or are we missing something here?

Here is the filepath.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <external-path name="external_storage_directory"
    path="." />
  <external-path name="files"
    path="Android/data/com.example.app/" />
</resources>

Here is the stacktrace:

E/MethodChannel#open_file( 8708): Failed to handle method call
E/MethodChannel#open_file( 8708): java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.app/app_flutter/files/my_folder/my_file.jpg
E/MethodChannel#open_file( 8708): 	at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:825)
E/MethodChannel#open_file( 8708): 	at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:450)
E/MethodChannel#open_file( 8708): 	at com.crazecoder.openfile.OpenFilePlugin.startActivity(OpenFilePlugin.java:170)
E/MethodChannel#open_file( 8708): 	at com.crazecoder.openfile.OpenFilePlugin.onMethodCall(OpenFilePlugin.java:109)
E/MethodChannel#open_file( 8708): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#open_file( 8708): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#open_file( 8708): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#open_file( 8708): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#open_file( 8708): 	at android.os.Handler.handleCallback(Handler.java:790)
E/MethodChannel#open_file( 8708): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#open_file( 8708): 	at android.os.Looper.loop(Looper.java:164)
E/MethodChannel#open_file( 8708): 	at android.app.ActivityThread.main(ActivityThread.java:6494)
E/MethodChannel#open_file( 8708): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#open_file( 8708): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/MethodChannel#open_file( 8708): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

OpenFile: 3.3.2 Flutter: 3.10.4 Tested on Android 8.1

I’ve put together a simple test app to recreate this issue. We are creating files within our app’s directory, yet OpenFile does not work, permissions aside it continues to fail via: PlatformException(error, Failed to find configured root that contains...).

Tested on Android 7 and 8.1

Configuring filepaths.xml with the following works for me when opening files via getApplicationDocumentsDirectory:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <files-path name="files-path"
    path="../" />
</paths>

The important bit is path="../".

I think what is happening is that “files-path” assumes a directory of /data/user/0/com.example.app/files and what we really need is /data/user/0/com.example.app/app_flutter. Therefore we back out of the “files” directory and into our app’s root directory.

However, this still seems to require “READ_EXTERNAL_STORAGE”. Is this correct?