skip to Main Content

I’m trying to open a URL but I get this Error, when I run an android app on the emulator or in a device the result on the screen is that nothing happens but I get "Unhandled Exception: MissingPluginException", but when I use windows app works fine.

launchUrl support: android, windows, ios

E/flutter ( 6260): [ERROR: flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method launch on channel plugins.flutter.io/url_launcher_android)
E/flutter ( 6260): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294:7)
E/flutter ( 6260):
E/flutter ( 6260): #1 _launchURL (package:peliculas/screens/details_cast.dart:371:8)
E/flutter ( 6260):

My code:

Future<void> _launchURL(String url) async {
  
  final Uri uri = Uri(scheme: "https", host: url);
  
  if (!await launchUrl(uri)) {
    throw 'Could not launch $url';
  }

-I’m using url ="www.google.com"
-emulator api 30

What I tried before: 
     - flutter clean
     - flutter pug get 
     - flutter run 
     - uninstall app 
     - flutter doctor -v   is OK
     - I'm not using hot restart or hot reload

UPDATE:
It happen in other projects but now is just in this one, I have another project where I use only this method and after updating closing and opening again starts to work but the main project didn’t work. I move the project to another place and open but I get the same.

SOLUTION:
To solve this problem, in my case that url_launcher didn’t work in my project but when I create a new one it works fine, just follow what "FirstComment" says, create a new project copy the lib folder to the new one, and set Manifest and pubspec configuration like the old project, also move other files like asset.

3

Answers


  1. run these commands in terminal

    1 : flutter clean

    2 : flutter pub get

    and Restart your app

    Login or Signup to reply.
  2. UPDATED

    You are using the url_launcher package which uses native device methods in order to work properly as also shown in the error

    No implementation found for method launch on channel

    Add the below code in AndroidManifest.xml above the <application> element

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

    Add the below code in Info.plist inside of <dict> element

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>https</string>
        <string>http</string>
    </array>
    

    Now, in the lib folder create a file launch_url.dart and paste the below code

          import 'package:flutter/material.dart';
          import 'package:url_launcher/url_launcher.dart';
    
          class LaunchUrl extends StatelessWidget {
          const LaunchUrl({super.key});
    
          @override
          Widget build(BuildContext context) {
            return Scaffold(
              appBar: AppBar(
                title: const Text('Launch Url'),
              ),
              body: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Center(
                    child: ElevatedButton(
                      onPressed:  () async => await _launchUrl('https://google.com/'),
                      child: const Text('Launch Url'),
                    ),
                  ),
                ],
              ),
            );
          }
    
          Future<void> _launchUrl([
            String? url,
          ]) async {
            if (!await launchUrl(Uri.parse(url!), mode: LaunchMode.externalApplication,)) {
              throw 'Could not launch $url';
            }
          }
          }
    

    Kindly uninstall the old app on your phone and run the below commands

    flutter clean

    flutter pub get

    After this run the app again and click on the button as shown below to open the url in the browser.

    <img src="https://i.stack.imgur.com/6nl3d.gif" alt="launch url in flutter">
    Login or Signup to reply.
  3. add this to your android manifest

    <queries>
            <!-- If your app opens https URLs -->
            <intent>
               <action android:name="android.intent.action.VIEW" />
               <category android:name="android.intent.category.BROWSABLE" />
               <data android:scheme="https" />
            </intent>
           
    </queries>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search