openFile static method

Future<bool> openFile(
  1. String filePath
)

打开文件 filePath 文件路径 /storage/emulated/0/Download/xxx.pdf 若不支持打开文件则返回false 由于Android 7.0 以上版本的限制,无法直接通过file://的方式来打开文件,需要通过FileProvider来打开

Implementation

static Future<bool> openFile(String filePath) async {
  LogUtils.println('filePath: $filePath');
  if (!File(filePath).existsSync()) {
    LogUtils.println('文件不存在');
    return false;
  }
  Uri uri = Uri(scheme: 'file', path: filePath);
  // 由于Android 7.0 以上版本的限制,无法直接通过file://的方式来打开文件,需要通过FileProvider来打开
  if (!kIsWeb && Platform.isAndroid && int.parse(await DeviceUtils.getSystemVersion()) >= 24) return false;
  if (!await onCanLaunchUrl(uri.toString())) return false;
  return await launchUrl(uri);
}