long
long

Reputation: 397

How to open the SD card directory to select a file with Flutter?

The function I want to achieve is to open the SD card directory after clicking a button, then I can select a PPT file, it will call the machine to view the PPT software to open, how can I achieve this function?

Upvotes: 2

Views: 1796

Answers (1)

Arto Bendiken
Arto Bendiken

Reputation: 2621

As @anmol.majhail mentioned in a comment earlier, use the flutter_document_picker plugin:

final String pptPath = await FlutterDocumentPicker.openDocument(
  params: FlutterDocumentPickerParams(
    allowedFileExtensions: ['ppt'],
    allowedMimeType: 'application/vnd.ms-powerpoint',
    allowedUtiTypes: ['com.microsoft.powerpoint.​ppt'],
  )
);

Once you have the file path, use the android_intent plugin to open it in a viewer app such as WPS Office:

if (platform.isAndroid) {
  final AndroidIntent intent = AndroidIntent(
    action: 'action_view',
    data: Uri.file(pptPath).toString(),
    arguments: {},
    package: 'cn.wps.moffice_eng', // optional
  );
  await intent.launch();
}

Upvotes: 1

Related Questions