-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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] When targeting API 30, canLaunch always retrurns false #63727
Comments
Flutter Doctor Output
|
Hi @Roshanalexander, |
Hi @darshankawar, The issue happens only on Android API level 30. Works fine on level <=29. Also, I'm unable to reproduce this issue on sample project. I'm using the following code in my project: if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: true,
enableJavaScript: true,
);
} else {
throw 'Could not launch $url';
} But if I take out the |
One thing I notice when I build my application is that, I get the following warning:
But I do not get this warning when I use a new sample application and use the url_launcher package. |
Hi @Roshanalexander, |
@darshankawar All URL's fail. I tried
This issue started happening after I upgraded Flutter from v1.17 to v1.20 |
Hi @Roshanalexander, Can you also try the official example on api 30 and see if you still experience the issue ? |
@darshankawar If you read what I said above, that's exactly what I said too. This issue is only happening on just my application. Even if I copy my code to the sample application, it works fine. That is why I came here looking for any suggestion to troubleshoot the issue. If you've got any input on how to figure out that, please let me know. |
Hey @darshankawar, I found the issue and can be reproduced on a fresh application. All you need to do is, modify the |
I'm also having the same issue when testing on a device running on API Level 30, |
I'm also experiencing this issue. |
Starting from API 30, there is a restriction on package visibility. This basically means that you will have to list all apps your app wants to interact with. This can be done by adding the If your app needs to interact with all the installed apps on the device, you can fall back to using the |
I can reproduce the issue code sampleimport 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
theme: ThemeData.dark(),
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Center(
child: Container(
child: Text('Hello World'),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () async => _launchURL(),
),
);
}
_launchURL() async {
const url = 'https://flutter.dev';
print("canLaunch ${await canLaunch(url)}");
// if (await canLaunch(url)) {
// await launch(url);
// } else {
// throw 'Could not launch $url';
// }
}
}
flutter doctor -v[✓] Flutter (Channel master, 1.22.0-10.0.pre.137, on Microsoft Windows [Version 10.0.19041.450], locale en-US)
• Flutter version 1.22.0-10.0.pre.137 at C:\Code\flutter_master
• Framework revision 37e2013774 (3 hours ago), 2020-09-11 04:05:02 -0400
• Engine revision bdaac368f8
• Dart version 2.10.0 (build 2.10.0-115.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Code\sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = C:\Code\sdk
• Java binary at: C:\Code\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
[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.2)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.7.30413.136
• Windows 10 SDK version 10.0.18362.0
[✓] Android Studio (version 4.0)
• Android Studio at C:\Code\android-studio
• Flutter plugin version 49.0.2
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[✓] VS Code (version 1.49.0)
• VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.14.1
[✓] Connected device (4 available)
• sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19041.450]
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 85.0.4183.102
• No issues found! |
Personally, I don't like the uncertainty that seems to come with using the QUERY_ALL_PACKAGES permission (because Google could stop letting people use it in the future). For that reason, I did some investigation and found that adding the following to my AndroidManifest.xml allows my app to open the browser, phone app and email app on API 30:
Just wanted to share in case it helps someone else out. |
Could you please show the whole manifest file or at least show the location to put these lines of code? |
@xuala69, the queries element should be nested within the manifest element (not the application element), like this:
|
@Wes1324 Thank you. Works like a charm |
Maybe this issue should be re-opened until the solution by @Wes1324 is documented on the pub.dev page for url_launcher? Because this is now mandatory setup on Android for the package to work. |
FYI to use
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
|
This fix works by generating an appBundle and running directly on the device.
Any workaround? Edit: I added
But this is not a really good fix. |
Would this also work for "mailto:" links? Edit: Tested, works. |
Please update this to the url_launcher docs, since this is mandatory for it to work |
A kind request to you for amending the URL launcher docs, this issue is serious and might affect all devices running API 30 or greater. |
Thank you Also, quit the app and run it again, hot reload and hot restart doesn't work. |
This solution works for everything except for the Youtube app. Google has clarified that it will not provide access to all apps from now Preview: Use of the broad package (App) visibility (QUERY_ALL_PACKAGES) permission and only give access to apps if the app depends on it like messaging will be accessible by payment apps etc. I am working on an app that needs to redirect to Youtube as a social media button. While using the QUERY_ALL_PACKAGES it works fine but since Google is restricting access now, how can I ask for Youtube permission only, if possible, mention it in . The webview for youtube is loading indefinitely and not working. |
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 |
url_launcher fails to launch website on
Android API level 30
with the following error:The text was updated successfully, but these errors were encountered: