Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[url_launcher] Works without doing the configuration of README #102630

Closed
juri180 opened this issue Apr 27, 2022 · 7 comments · Fixed by flutter/plugins#5424
Closed

[url_launcher] Works without doing the configuration of README #102630

juri180 opened this issue Apr 27, 2022 · 7 comments · Fixed by flutter/plugins#5424
Assignees
Labels
p: url_launcher Plugin to launch external applications P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version

Comments

@juri180
Copy link

juri180 commented Apr 27, 2022

The configuration section in the README says that some configuration is necessary on iOS and Android.

  • iOS: You've to add any URL schemes you're using to your Info.plist.
  • Android: For API >=30 you've to add a <queries> element to the AndroidManifest.xml.

I tried to use the package for https and http without doing the configuration and everything worked. Tested with Android Emulator Pixel 3 API 30 and iPhone 13 iOS 15.2 on Simulator.

Why should I do the configuration, if it works also without? Or does it work only because of the Emulator/Simulator? It would be nice to have this in the documentation.

@maheshmnj maheshmnj added the in triage Presently being triaged by the triage team label Apr 27, 2022
@maheshmnj
Copy link
Member

Hi @juri180, Thanks for filing the issue. I suspect that you are directly launching the URLs without querying the apps that can handle the URL. If you try the below code sample without adding queries to manifest, You will get the exception.

  _launchUrl() async {
    final uri = Uri.parse('https://flutter.dev');
    if (await canLaunchUrl(uri)) {
      await launchUrl(uri);
    } else {
      throw 'Could not launch $uri';
    }
  }

This exception is more common on recent Android versions. It is because the canLaunch looks for the URL handlers on the device and queries are required to look for those handlers.

As stated in the doc comments of canLaunchUrl

Checks whether the specified URL can be handled by some app installed on the device.

Returns true if it is possible to verify that there is a handler available. A false return value can indicate either that there is no handler available, or that the application does not have permission to check. For example:

On recent versions of Android and iOS, this will always return false unless the application has been configuration to allow querying the system for launch support. See the README for details.

@maheshmnj maheshmnj added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 27, 2022
@stuartmorgan stuartmorgan added plugin p: url_launcher Plugin to launch external applications P2 Important issues not at the top of the work list and removed waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds in triage Presently being triaged by the triage team labels Apr 27, 2022
@stuartmorgan stuartmorgan self-assigned this Apr 27, 2022
@stuartmorgan
Copy link
Contributor

There is a documentation issue here that I missed when updating the docs for the new API and reworked the discussion of canLaunch. We shouldn't be showing http(s) in the queries section, as there's almost no use case where someone would actually need to canLaunch check an http(s) URL on any of our supported platforms; browsers are pretty much always available. We also incorrectly comment the Android queries permission example as being about launching rather than querying.

@stuartmorgan
Copy link
Contributor

stuartmorgan commented Apr 27, 2022

If you try the below code sample without adding queries to manifest, You will get the exception.

@maheshmnj Please don't demonstrate that sample going forward; it's unfortunate that the plugin ever suggested it in the first place, because it's actually an anti-pattern. launch will throw on failure already, so in that construction the canLaunch check is at best just pointless, and at worst causes issues (false negatives, unnecessary additions of query permissions).

I've already scrubbed it from the app-facing package, and I'll be updating the implementation packages to match shortly.

@juri180
Copy link
Author

juri180 commented Apr 27, 2022

Thanks for your quick responses.

@maheshmnj I've tested the package with exactly the same code that you've provided and it worked for me without doing the configuration steps of the README on the test devices mentioned in the first message. I've also checked the Info.plist and AndroidManifest.xml to make sure that it's not already there.

@stuartmorgan Do I understand it correctly, that the Configuration section in the README for iOS and Android is indeed not necessary for simple http(s) launches?
And good to know, that this code snippet is not recommended. I've been using this implementation for a long time, because of the documentation.

@maheshmnj
Copy link
Member

maheshmnj commented Apr 27, 2022

Thanks for the feedback @stuartmorgan, I had a misunderstanding that canLaunchUrlmust be used before launching any URL. This is clear now. Perhaps the new updates to the documentation will clarify this.

@stuartmorgan
Copy link
Contributor

Do I understand it correctly, that the Configuration section in the README for iOS and Android is indeed not necessary for simple http(s) launches?

There are two parts to answering this:

  • The configuration described in the README is never required for launches (launchUrl). It is only required for queries (canLaunchUrl). There is no need to query as part of the launch flow.
  • Whether canLaunchUrl for a given scheme requires permissions is entirely up to the OS. On Android, it is documented that some applications are always visible. I haven't checked the adb shell dumpsys package queries, but I would not be surprised if the bundled browser is visible. According to Apple's docs "This method always returns NO for undeclared schemes"; it's certainly possible that this is not actually enforced for http(s), but the documented behavior is that it will fail, so that could become true at any time even if it's not currently.

stuartmorgan added a commit to stuartmorgan/plugins that referenced this issue Apr 27, 2022
Improves the README section about query permissions:
- Removes http/https from the examples; we don't actually expect people
  to query for http(s) support in general (since generally a browser can
  assumed to be available), so it's an odd thing to show.
- Updates the comments in the Android example to clarify that it's about
  querying for support, not launching.
- Makes the iOS and Android sections have parallel structure so they are
  easier to read.

Fixes flutter/flutter#102630
@maheshmnj maheshmnj added the r: fixed Issue is closed as already fixed in a newer version label Jun 8, 2022
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2022
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: url_launcher Plugin to launch external applications P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants