26

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
Faizan Kamal
  • 1,732
  • 3
  • 27
  • 56

8 Answers8

49

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" />
Gert Steenkamp
  • 517
  • 3
  • 3
  • 10
    Thanks a lot! Adding permission only worked well, had the same issue with API Level 30. – Fellow7000 Apr 05 '21 at 14:48
  • 3
    Adding the permission worked for me too, however I had to uninstall and re install the app. Flutter clean did not rebuild with manifest changes. – Ali Akber Apr 29 '21 at 10:47
  • 5
    It looks like the url_launcher package now has documentation for this, but recommends a different approach. See @RITTIK 's answer below or check out https://pub.dev/packages/url_launcher#android – Developer Extraordinare Feb 23 '22 at 13:23
  • 5
    Google is cracking down on QUERY_ALL_PACKAGES, so this solution is better avoided. Speaking in April 2022. – kbrmys Apr 08 '22 at 15:16
  • 1
    did u find the solution.. my app got rejected due to i used QUERY_ALL_PACKAGES – Soundhar Raj Oct 13 '22 at 07:38
  • QUERY_ALL_PACKAGES is NOT the way to fix that issue - your app will be rejected. You have to update Flutter to 2+, update url_launcher version and include tags in Android's manifest file: – Matt Oct 14 '22 at 08:28
14

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

Kien Vu
  • 460
  • 4
  • 8
10

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

rduque
  • 291
  • 3
  • 5
3

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.

imgkl
  • 1,013
  • 1
  • 7
  • 24
  • After upgrading flutter and url launcher version, everything is working fine in debug mode. How can I launch application in release mode? I want to test app before uploading it to google playstore. – Faizan Kamal Jan 25 '21 at 12:32
  • 1
    " flutter build apk --release " or check the accepted answer of this question https://stackoverflow.com/questions/51000869/flutter-how-to-make-release-version-in-android-studio – imgkl Jan 25 '21 at 12:37
3

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

benjiDev
  • 41
  • 3
1

If you are trying out the URL launcher in Android and the device API is 30+, try adding the query intent outside of the application tag in the Android Manifest.

<queries>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
</queries>
Adeel Nazim
  • 640
  • 6
  • 17
0

add permission to <AndroidManifest.xml> under the <manifest ... package="com.example.app": Hot restart or you have to uninstall app and install it again

0

To begin with AndroidManifest.xml add the below code,

<queries>
  <!-- If your app checks for url support -->
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
</queries>




class MapsUtils
{
  MapsUtils._();

  //latitude and longitude

  static Future<void> openMapWithPosition(double latitude, double longitude) async
  {
    String googleMapUrl = "https://www.google.com/maps/search/?api=1&query=$latitude,$longitude";

    if (await canLaunchUrlString(googleMapUrl))
      {
        await launchUrlString(googleMapUrl, mode: LaunchMode.externalApplication);
      }
    else
      {
        throw "Could not open map.";
      }
  }

  //text address
  static Future<void> openMapWithAddress(String completeAddress) async
  {
    String query = Uri.encodeComponent(completeAddress);
    String googleMapUrl = "https://www.google.com/maps/search/?api=1&query=$query";

    if (await canLaunchUrlString(googleMapUrl))
    {
      await launchUrlString(googleMapUrl, mode: LaunchMode.externalApplication);
    }
    else
    {
      throw "Could not open map.";
    }
  }

}

for More info laucher

Balaji
  • 1