簡體   English   中英

如何使用Flutter打開SD卡目錄以選擇文件?

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

我要實現的功能是單擊按鈕后打開SD卡目錄,然后我可以選擇一個PPT文件,它將調用本機查看PPT軟件打開,如何實現此功能?

正如@ anmol.majhail在前面的評論中提到的,請使用flutter_document_picker插件:

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

有了文件路徑后,請使用android_intent插件在查看器應用程序(例如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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM