Guard external link launch in the changelog WebView#179
Open
jim-daf wants to merge 1 commit into
Open
Conversation
The What's New WebView routes links out with a raw startActivity(ACTION_VIEW). When no app on the device can open the URI that call throws ActivityNotFoundException and the screen crashes. Wrap the launch in a try/catch and show a short toast when nothing can open the link.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The What's New screen renders the changelog in a WebView and routes any tapped link out with a raw
startActivity(Intent(Intent.ACTION_VIEW, url)). When no installed app can handle the link that call throwsActivityNotFoundExceptionand the screen crashes.This wraps the launch in a try/catch and shows a short toast when nothing can open the link, using the existing
showToastextension. Links that resolve behave exactly as before.Change
app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewFragment.kt:val url = request?.url ?: return false //you can do checks here e.g. url.host equals to target one - startActivity(Intent(Intent.ACTION_VIEW, url)) + try { + startActivity(Intent(Intent.ACTION_VIEW, url)) + } catch (e: ActivityNotFoundException) { + showToast("No app found to open this link") + } return true