Skip to content

[url_launcher] canLaunch can return false for http(s) links with a specific application handler #93765

@elvisun

Description

@elvisun

Steps to Reproduce

  1. Run on Android 11+
  2. Install amazon on your phone
  3. Write a flutter app that runs canLaunch('https://www.amazon.com')
  4. This will return false when it should return true
  5. However, canLaunch('https://amazon.com') will return true, I'm not entirely sure why, might have something to do with the amazon app setup?

My guess is that this is related to this line:
https://github.com/flutter/plugins/blob/b548ae18646d1725a8e1f004c26bf42e4d362aa8/packages/url_launcher/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncher.java#L84

According to this blog post,

In Android 11 there’s a better way to do this, which avoids the need to query other apps: the FLAG_ACTIVITY_REQUIRE_NON_BROWSER intent flag. When you call startActivity() with this flag, an ActivityNotFoundException will be thrown if a browser would have been launched. When this happens, you can open the URL in a Custom Tab instead.

So should the ActivityNotFoundException handling be more forgiving?

Setup

AndroidManifest.xml:

...
    <!-- Provide required visibility configuration for API level 30 and above -->
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="https" />
        </intent>
    </queries>

...
Logs
[√] Flutter (Channel stable, 2.5.2, on Microsoft Windows [Version 10.0.19043.1348], locale en-US)
    • Flutter version 2.5.2 at D:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3595343e20 (7 weeks ago), 2021-09-30 12:58:18 -0700
    • Engine revision 6ac856380f
    • Dart version 2.14.3

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\1\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 51.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Community Edition (version 2017.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.3
    • Flutter plugin version 21.2.2
    • Dart plugin version 172.3968.27

[√] Connected device (3 available)
    • Pixel 5 (mobile) • 13151FDD4000NV • android-arm64  • Android 12 (API 31)
    • Chrome (web)     • chrome         • web-javascript • Google Chrome 95.0.4638.69
    • Edge (web)       • edge           • web-javascript • Microsoft Edge 93.0.961.52

• No issues found!

Metadata

Metadata

Labels

P1High-priority issues at the top of the work liste: OS-version specificAffects only some versions of the relevant operating systemp: url_launcherPlugin to launch external applicationspackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions