Skip to content

[Bug]: App crashes with ActivityNotFoundException when no browser compatible with custom tabs is available on Android device #182

@nnitu-bd

Description

@nnitu-bd

Description

The Android app crashes with an unhandled ActivityNotFoundException when attempting to authenticate on a device that doesn't have Chrome or any compatible custom chrome tabs browser installed.

Proposed fix:

try {
    if (callbackScheme == "https" && callbackHost != null && callbackPath != null) {
        intent.launch(this, authLauncher, authenticationUri, callbackHost!!, callbackPath!!)
    } else {
        intent.launch(this, authLauncher, authenticationUri, callbackScheme)
    }
    authStarted = true
} catch (e: android.content.ActivityNotFoundException) {
    Log.e(LOG_TAG, "ActivityNotFoundException: No browser available", e)
    val callback = FlutterWebAuth2Plugin.callbacks[callbackScheme]
    callback?.error("NO_BROWSER", "No browser available on this device.", e.message)
    FlutterWebAuth2Plugin.callbacks.remove(callbackScheme)
    finish()
}

Minimal Reproduction

Steps to reproduce the behaviour:
Run the app on an Android device/emulator without Chrome or any browser installed
Trigger authentication using FlutterWebAuth2.authenticate()
App crashes immediately

  1. Use the following code:
    <Paste your code here>
  2. [...]

Exception or Error

E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Caused by: android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.VIEW ... pkg=com.android.chrome }

Expected Behaviour

The error should be caught and returned to Flutter as a PlatformException, allowing the app to handle it gracefully (e.g., show an error message to the user).

Screenshots

No response

Additional context

No response

Device

Samsung S22 Ultra

OS

Android 16

Browser

Opera (only opera available on the device)

Flutter version

3.32.8

flutter_web_auth_2 version

5.0.0-alpha.7

Checklist

  • I have read and followed the entire troubleshooting guide and it has not provided the solution I need.
  • I have provided all the information I can.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions