openDocumentFileWithResult function

Future<OpenDocumentFileResult> openDocumentFileWithResult(
  1. Uri uri
)

It's a convenience method to launch the default application associated with the given MIME type and can't be considered an official SAF API.

Launch ACTION_VIEW intent to open the given document uri.

Returns a OpenDocumentFileResult that allows you handle all edge-cases.

Implementation

Future<OpenDocumentFileResult> openDocumentFileWithResult(Uri uri) async {
  try {
    await kDocumentFileHelperChannel.invokeMethod<void>(
      'openDocumentFile',
      <String, String>{'uri': '$uri'},
    );
    return OpenDocumentFileResult.launched;
  } on PlatformException catch (e) {
    switch (e.code) {
      case 'EXCEPTION_ACTIVITY_NOT_FOUND':
        return OpenDocumentFileResult.failedDueActivityNotFound;
      case 'EXCEPTION_CANT_OPEN_FILE_DUE_SECURITY_POLICY':
        return OpenDocumentFileResult.failedDueSecurityPolicy;
      case 'EXCEPTION_CANT_OPEN_DOCUMENT_FILE':
      default:
        return OpenDocumentFileResult.failedDueUnknownReason;
    }
  }
}