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

Android system file browser cannot be invoked #1909

Closed
t-arn opened this issue Apr 28, 2023 · 1 comment · Fixed by #1910
Closed

Android system file browser cannot be invoked #1909

t-arn opened this issue Apr 28, 2023 · 1 comment · Fixed by #1910
Labels
bug A crash or error in behavior.

Comments

@t-arn
Copy link
Contributor

t-arn commented Apr 28, 2023

Describe the bug

I tried to invoke Android's system file browser UI (SAF) but get following error message:
No appropriate Activity found to handle this intent.

Steps to reproduce

Try following code:

from android.content import Intent

intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE) 
intent.setType("*/*")
result = await self.app._impl.intent_result(intent) 

Expected behavior

The system file browser should open because under my Android 13, it is definitely there.

With following code, the file browser is shown, but the app doesn't wait for the result:

intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE) 
intent.setType("*/*")
result = await self.app._impl.native.startActivityForResult(intent, 1234) 

I get the error back object NoneType can't be used in 'await' expression

Screenshots

No response

Environment

  • Operating System: Android 13
  • Python version: 3.11
  • Software versions:
    • Toga: 0.3.1dev93

Logs


Additional context

The same problem exists with Intent.ACTION_CREATE_DOCUMENT and this Intent also can be invoked directly with startActivityForResult

The problem stems from this code in app.py:

if not intent.resolveActivity(self.native.getPackageManager()):
            raise RuntimeError("No appropriate Activity found to handle this intent.")

This may be a good way to find Activities of standard apps, but it seems to fail in the case of internal Activities like the system file browser.

It might be better to remove this code and instead catch and return exceptions that occur when invoking startActivityForResult unguarded

@mhsmith
Copy link
Member

mhsmith commented May 31, 2023

For future reference: there's a complete example of using the system file browser at #1158 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants