Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openDocumentFileWithResult - OpenDocumentFileResult.failedDueActivityNotFound #158

Open
hayesOw opened this issue May 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hayesOw
Copy link

hayesOw commented May 29, 2024

Describe the bug
Cannot open file after writing using openDocumentFileWithResult, the file is written correctly and can be found via DocumentFile

Expected behavior
Open with dialog to open, I have a few file manager apps so they must be able to open the file

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: Oneplus 5t
  • OS: Android 14
  • Browser Chrome
    Additional context

Code example

  Future<DocumentFile?> getSafDirectory() async {
    final List<UriPermission>? grantedUris = await persistedUriPermissions();

    Uri? grantedUri = grantedUris != null && grantedUris.isNotEmpty
        ? grantedUris.first.uri
        : await saf.openDocumentTree();

    if (grantedUri == null) {
      return null;
    }

    DocumentFile? grantedDirectory = await grantedUri.toDocumentFile();

    if (grantedDirectory == null) {
      return null;
    }

    DocumentFile? amaraDirectory =
        await grantedDirectory.findFile('AmaraHealth') ??
            await saf.createDirectory(grantedUri, 'AmaraHealth');

    return amaraDirectory;
  }

  Future<bool> openAndroid() async {
    DocumentFile? amaraDirectory = await getSafDirectory();

    if (amaraDirectory == null) {
      return false;
    }

    DocumentFile? file = await amaraDirectory.findFile('$fileName.$ext');

    if (file == null) {
      return false;
    }

    OpenDocumentFileResult result = await openDocumentFileWithResult(file.uri);

    return true;
  }
@hayesOw hayesOw added the bug Something isn't working label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant