Skip to content

MainActivity WebView can crash on links no installed app can open #14

@jim-daf

Description

@jim-daf

MyWebViewClient.shouldOverrideUrlLoading in app/src/main/java/org/olgsoft/apipepanic/MainActivity.java forwards every URL the embedded game page navigates to with a plain startActivity(Intent.ACTION_VIEW, ...):

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    return true;
}

The call is unguarded. If the device has no installed app that handles the URI scheme of the link the page tries to open, startActivity throws ActivityNotFoundException and tears the Activity down mid-game.

This is reachable today on:

  • Tablets / TVs / form factors that ship without a default browser.
  • Stripped-down GSI / custom ROM builds where the browser has been removed.
  • Users who have manually disabled their browser via pm disable.

The fix is local: wrap the startActivity call in try / catch (ActivityNotFoundException) and show a Toast so the failure stays scoped to that single click. Happy to open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions