Skip to content

fix: show permission screen for missing storage access#21280

Draft
onurds wants to merge 1 commit into
ankidroid:mainfrom
onurds:fix-16786-permission-screen
Draft

fix: show permission screen for missing storage access#21280
onurds wants to merge 1 commit into
ankidroid:mainfrom
onurds:fix-16786-permission-screen

Conversation

@onurds

@onurds onurds commented Jun 16, 2026

Copy link
Copy Markdown

Purpose / Description

Shortcuts and share intents can currently fail when AnkiDroid is missing the required collection storage permission. Instead of guiding the user through the existing permission screen, some flows show a toast or can crash when startup continues without permission.

This can happen after the permission is manually revoked, Android removes it after long inactivity, or the app is opened through a shortcut or share target before permission is granted again.

I saw that there is broader planned work in #21204 to improve collection creation and startup permission handling. That work should give this area a cleaner long term shape, but it is larger architecture work. This PR is a smaller fix that can stay in place until that refactor lands.

Fixes

Approach

Replaced the toast only missing permission handling with the existing PermissionsActivity flow.

For activities that require collection access during startup, missing permission now opens the permission screen and postpones the original target intent through DeckPicker until startup completes.

The previous activity is finished immediately, which avoids partially initialized screens such as Card Browser continuing lifecycle work without the expected startup state.

Intent handlers now use the same folder permission check as startup and route missing permission cases through PermissionsActivity.

For external share intents with stale content:// grants, DeckPicker now catches SecurityException when attempting to resume the deferred intent.

This prevents the app from crashing.

In that rare case the user may land on the home screen after granting permission and can retry the share action.

How Has This Been Tested?

  • Tested manually with app shortcut actions after revoking permission.
  • Card Browser and Study shortcuts open the permission screen instead of crashing.
  • Share and image intent stale URI crash no longer closes the app.
  • Ran focused unit tests: CardBrowserTest.startupFromCardBrowserActionItemShouldOpenPermissionsActivityIfNoPermissions, IntentHandlerPermissionTest, IntentHandlerTest.
  • Ran ktlint checks: :AnkiDroid:ktlintMainSourceSetCheck, :AnkiDroid:ktlintTestSourceSetCheck.
  • Ran git diff --check.

Screenshots

N/A. This uses the existing permission screen.

Checklist

  • You have a descriptive commit message with a short title, first line max 50 chars.
  • You have commented your code, particularly in hard to understand areas.
  • You have performed a self review of your own code.
  • UI changes include screenshots of all affected screens.
  • UI changes have been tested using the Google Accessibility Scanner.

@welcome

welcome Bot commented Jun 16, 2026

Copy link
Copy Markdown

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shortcuts/share to ankidroid should not crash the app when the file permissions are missing

1 participant