3

I have a specific path where user files are exported under the following path:
e.g : /storage/emulated/0/Android/data/com.example.app_name/files
However the problem is not how generate the path but how to do this redirection (open the folder where the file is stored). I've tried to use the plugin url_launcher but apparently it doesn't work.I tried to launch this path as url:
code example :

FlatButton(
    onPressed: () async{
        // _localPath returns /storage/emulated/0/Android/data/com.example.app_name/files 
        final path = await _localPath;
        if (await canLaunch(path)) {
            await launch(path);
        } else {
            throw 'Could not launch $path';
          }
        },
    child: Text('Navigate to App storage Folder'),
      ),

The user exported the data as csv file and he want to use that file.
The expected result : user will be redirected to the path (folder files) and exit the Flutter application. PS : I'm targeting only Android Platform.

Houssem
  • 6,409
  • 3
  • 18
  • 28
  • did you see this ... https://stackoverflow.com/questions/59053056/how-to-open-a-csv-file-like-url-launcher-in-flutter – Sajjad Sep 27 '20 at 14:42
  • another way... https://stackoverflow.com/questions/59364498/how-to-open-audio-file-from-file-manager-using-flutter-app – Sajjad Sep 27 '20 at 14:42
  • Those questions about openning files, my question is : How to redirect the user out of the application without openning the file. – Houssem Sep 27 '20 at 14:44
  • @Houssem Have you been to try my answer? – J. S. Sep 30 '20 at 12:07
  • @JoãoSoares I'm trying,now still can't access to the android/data/com.example.../files, i'll accept it just let me verify some things so I can also provide useful informations about the problem.For now I think we can't access `../Android/data/..` so as an alternative i'll try to do the work in Download Folder. – Houssem Sep 30 '20 at 12:26
  • Some directories might be protected. Are you trying to access files inside your app itself? (based on the path /com.example...) – J. S. Sep 30 '20 at 12:58
  • Yes under my app files. – Houssem Sep 30 '20 at 13:48
  • If I understood correctly, you are trying to access files that are inside your actual app package? Someone who knows more about Android should correct me, but I believe those are protected and you can't access them. – J. S. Sep 30 '20 at 19:47
  • @Houssem Does working on the Downloads folder work for you? – J. S. Oct 01 '20 at 18:57
  • @JoãoSoares I tried it in phone storage under a folder that I created and stored the file there and it works but the file manager doesn't go to the provided path but a default one.Also I stored the file under ..app/files but when i access the file manager doesn't suggest the correct path but a default one too (categories) but idk it depends on the phone model maybe cause the result on emulator and my testing phone not the same.also i want to mention that there is changes in the upcoming android 11 : https://developer.android.com/about/versions/11/privacy/storage#manage-device-storage – Houssem Oct 01 '20 at 21:46
  • This issue is different from the original question, which was regarding sending the user from an app to a specific folder. So if the answer solved your issue, please mark it as correct and ask a new question regarding restricted directories in devices. – J. S. Oct 02 '20 at 23:26
  • The issue still the same now that `OpenFile.open(my_path)` doesn't open the right path but give a suggestion how to continue and if you continue with File Manager It opens a default path and not the given path.it does not open the given path where the file stored even if the stored file is directly under storage /sdcard/0/MyFolder/. – Houssem Oct 03 '20 at 12:10

1 Answers1

3

I seem to have found a solution for your question with a package called open_file. You can simply point to the path you want to open and it will ask the OS for the app you want to use to handle files or use what is set as your default.

Basic code example:

class OpenDirectoryPath extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: RaisedButton(
        child: Text('Open path'),
        onPressed: () {
          _openPath('/storage/emulated/0/Download/');
        },
      ),
    );
  }

  void _openPath(String path) async {
    OpenFile.open(path);
  }
}

(tested in Android)

J. S.
  • 8,905
  • 2
  • 34
  • 44
  • I find your answer useful but it's not a definitve answer since The File Manager doesn't open the given path.but a default path that the File Manager will provide.Paths i tried : under files folder of my app and directly under a custom folder in phone storage. – Houssem Oct 03 '20 at 12:20
  • It seems that I made the mistake of using the default Download directory as the example, and the Android File Manager was already open on that same folder. So it's simply switching the apps. I am starting to really believe this is not possible to do unless the File Manager app accepts a parameters that tells it which path you want to send the user to. And since you can't control what app the user will be utilizing, then you can't do this. – J. S. Oct 03 '20 at 12:47