Skip to content

fix: reset package name in intent on open link error - #1320

Open
NatsuCamellia wants to merge 1 commit into
ReadYouApp:mainfrom
NatsuCamellia:missing-browser
Open

fix: reset package name in intent on open link error#1320
NatsuCamellia wants to merge 1 commit into
ReadYouApp:mainfrom
NatsuCamellia:missing-browser

Conversation

@NatsuCamellia

Copy link
Copy Markdown
Contributor

Problem

If a user selects a specific browser for opening links and later uninstalls it, the app crashes every time they open a link. This is because the catch block reuses the same Intent, which still carries the uninstalled browser's package name.

Reproduction

  1. Set a specific browser for opening links.
  2. Uninstall that browser.
  3. Open any article linkr in the app.

Fix

Reset the package on the ACTION_VIEW intent before retrying to fallback to other browsers.

Note

The stale browser preference is not cleared, so every subsequent link still shows the "something went wrong" toast. Maybe we can also reset the preference.

Related

@ibrahim-iqbal ibrahim-iqbal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, focused fix. Clearing the package binding with intent.setPackage(null) on the retry drops the reference to the uninstalled browser and hands the choice back to the system, which is exactly what the fallback wants to do.

One tiny follow-up (non-blocking, edge case): the retry startActivity inside the outer catch isn't wrapped in another try/catch, so on a device with no browser installed at all it would throw ActivityNotFoundException and crash. That's the same behaviour that existed before this PR — the fix here still shrinks the crash surface for the common "uninstalled preferred browser" case, which is the reported bug — but if you want to fully harden it you could catch the retry too, or use resolveActivity before calling startActivity. Happy to leave that for a follow-up.

Both call sites (AppUriHandler and Context.openURL) get the same one-line fix, which keeps the two paths in sync.

@NatsuCamellia

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I can fix the issue as well, but it needs some time as I'm pretty busy recently.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants