Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter url_launcher is not launching url in release mode

I don't know for some reason url_launcher (https://pub.dev/packages/url_launcher) is not working after downloading app from google playstore. In debug mode it is working the way it should be. But after uploading app on playstore and downloading it from there, url launcher is not launching any url. WHY is that?

import 'package:url_launcher/url_launcher.dart';

 onTap: () {
  launchURL("https://www.google.com");
},
..............
  launchURL(String url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

pubspec.yaml url_launcher: ^5.7.6

I've also added android.permission.INTERNET

I'm not using latest version of url_launcher so may be using latest version will solve the issue BUT problem with it is that latest version of url_launcher needs latest version of flutter. Is it safe to upgrade flutter version? I can't take a risk of causing any more issues as my app is already in production

This is what I get when I try to upgrade to url_launcher: ^5.7.10 which is the latest version and run flutter pub get

[xxxxx] flutter pub get
Running "flutter pub get" in xxxxx...                       
The current Flutter SDK version is 1.22.0-9.0.pre.

Because url_launcher >=5.7.7 <6.0.0-nullsafety depends on url_launcher_platform_interface >=1.0.9 <2.0.0-nullsafety which requires Flutter SDK version >=1.22.0 <2.0.0, url_launcher >=5.7.7 <6.0.0-nullsafety is forbidden.

So, because xxxxx depends on url_launcher ^5.7.10, version solving failed.
pub get failed (1; So, because storeifie depends on url_launcher ^5.7.10, version solving failed.)
exit code 1
like image 957
Faizan Kamal Avatar asked Jan 25 '21 11:01

Faizan Kamal


People also ask

How do I open mail in Flutter?

Open Mail App Flutter. A boring but accurate name. This library provides the ability to query the device for installed email apps and open those apps. If you just want to compose an email or open any app with a mailto: link, you are looking for url_launcher.


Video Answer


5 Answers

I had the same problems with Android 11 (API level 30) - everything worked well before software update (and on my test device that is running earlier version) - The following seems to have put me on the right track https://developer.android.com/training/basics/intents/package-visibility#all-apps

I solved my problem by adding the following in the AndroidManifest.xml (although it may not be necessary.)

<activity android:name="io.flutter.plugins.urllauncher.WebViewActivity"
           android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
           android:exported="false"/>

That alone did not work, and then I added to the lines just below <manifest ... package="com.example.app":

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
like image 100
Gert Steenkamp Avatar answered Oct 23 '22 12:10

Gert Steenkamp


I skipped calling canLaunch(url) and call launch(url) in try-catch, it's work

like image 34
tdt kien Avatar answered Oct 23 '22 13:10

tdt kien


Looks like since API 30 of Android you should need to add explicit the intents you will do. for example if you will open a URL you will need to add the following code to your AndroidManifest.

<queries>
    <!-- to opens https URLs -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https" />
    </intent>
</queries>

You can see the update in the url_launcher read.me: https://pub.dev/packages/url_launcher

like image 41
rduque Avatar answered Oct 23 '22 13:10

rduque


First of all, you are on dev channel of the flutter (1.22.0-9.0.pre is a dev version, released on 2/9/2020). Since your app is in production, please change the channel to stable, since it has no breaking bugs.

flutter channel stable

and then do flutter upgrade.

 flutter upgrade

Now, try to upgrade the url_launcher package to the latest version. It should work.

PS: Don't worry about flutter upgrading, as long as you are upgrading in the stable branch. it is always recommended to run the latest version.

like image 41
imgkl Avatar answered Oct 23 '22 12:10

imgkl


I directly used launch() in a try-catch block without any condition of canLaunch() and it worked fine

like image 26
benji Avatar answered Oct 23 '22 11:10

benji