7

How to open a file by default application using flutter? For example, I have a .txt file and want to open it using the device's default application. I think that there should be something like Process.Start() from .Net.

Ruben Martirosyan
  • 870
  • 1
  • 12
  • 23

2 Answers2

18

open_file plugin helped, nevermind.


Update from Vishnu Haridas comment:

open_file has unnecessary permission REQUEST_INSTALL_PACKAGES and your app can get rejected from Google Play if the target API level is 30 (Android 11 R). An alternative solution is to use open_file_plus or url_launcher.

Ruben Martirosyan
  • 870
  • 1
  • 12
  • 23
  • 1
    `OpenFile.open(filePath);` – Soon Santos Jun 10 '20 at 23:14
  • does it work with doc/docx ? in my case it opens pdf but not doc files. – Hardik Vaghani Sep 24 '21 at 09:23
  • I haven't tried with the .doc file, but it works with xlsx. But what happens when you try to open .doc? Are you sure that there's an application for .doc files on the phone? – Ruben Martirosyan Sep 24 '21 at 10:27
  • 4
    `open_file` has unnecessary permission **`REQUEST_INSTALL_PACKAGES`** and your app can [get rejected from Google Play](https://support.google.com/googleplay/android-developer/answer/10158779) if the target API level is 30 (Android 11 R). An alternative solution is to use `open_file_plus` or `url_launcher`. – Vishnu Haridas Sep 27 '22 at 16:44
  • Seems like this is a new restriction, I'll add in my answer – Ruben Martirosyan Sep 28 '22 at 10:37
2

open_file plugin didn't worked for me.

And that's where Android_Intent came to rescue.

In my case the meme type was video. And that's why following snippet seems to be working.

String path = "your_local_file_path";

final AndroidIntent intent = AndroidIntent(
        action: 'action_view',
        data: Uri.encodeFull(path),
        type: "video/*");
intent.launch();

Update: addroid_intent has been discontinued and replaced with the community package android_intent_plus

Samuel Nde
  • 2,565
  • 2
  • 23
  • 23
Tushar Pol
  • 7,119
  • 14
  • 29
  • 36