Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – I want to launch WhatsApp application from my flutter application

Posted on November 14, 2022

Solution 1 :

You are missing the https:// in your url.

Replace the code below with your url() method:

  String url() {
    if (Platform.isAndroid) {
      // add the [https]
      return "https://wa.me/$phone/?text=${Uri.parse(message)}"; // new line
    } else {
      // add the [https]
      return "https://api.whatsapp.com/send?phone=$phone=${Uri.parse(message)}"; // new line
    }
  }

Solution 2 :

I found a solution adding this code to android/app/src/main/AndroidManifest.xml

<queries>
<intent>
    <action android_name="android.intent.action.VIEW" />
    <data android_scheme="https" />
</intent>
<intent>
    <action android_name="android.intent.action.DIAL" />
    <data android_scheme="tel" />
</intent>
<intent>
    <action android_name="android.intent.action.SEND" />
    <data android_mimeType="*/*" />
</intent>

Solution 3 :

 String url() {
      if (Platform.isIOS) {
        return "whatsapp://wa.me/$phone/?text=${Uri.encodeFull(message)}";
      } else {
        return "whatsapp://send?phone=$phone&text=${Uri.encodeFull(message)}";
      }
    }

Solution 4 :

This worked me by adding this code to android/app/src/main/AndroidManifest.xml below </Application> Tag:

<queries>
        <!-- If your app opens https URLs -->
        <intent>
            <action android_name="android.intent.action.VIEW" />
            <data android_scheme="https" />
        </intent>
        <!-- If your app makes calls -->
        <intent>
            <action android_name="android.intent.action.DIAL" />
            <data android_scheme="tel" />
        </intent>
        <!-- If your sends SMS messages -->
        <intent>
            <action android_name="android.intent.action.SENDTO" />
            <data android_scheme="smsto" />
        </intent>
        <!-- If your app sends emails -->
        <intent>
            <action android_name="android.intent.action.SEND" />
            <data android_mimeType="*/*" />
        </intent>
    </queries>

Method i used to open Whatsapp:

void openWhatsapp(
      {required BuildContext context,
      required String text,
      required String number}) async {
    var whatsapp = number; //+92xx enter like this
    var whatsappURlAndroid =
        "whatsapp://send?phone=" + whatsapp + "&text=$text";
    var whatsappURLIos = "https://wa.me/$whatsapp?text=${Uri.tryParse(text)}";
    if (Platform.isIOS) {
      // for iOS phone only
      if (await canLaunchUrl(Uri.parse(whatsappURLIos))) {
        await launchUrl(Uri.parse(
          whatsappURLIos,
        ));
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
            const SnackBar(content: Text("Whatsapp not installed")));
      }
    } else {
      // android , web
      if (await canLaunchUrl(Uri.parse(whatsappURlAndroid))) {
        await launchUrl(Uri.parse(whatsappURlAndroid));
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
            const SnackBar(content: Text("Whatsapp not installed")));
      }
    }
  }

Solution 5 :

The plugin works fine, but you need to add the permissions in the android manifest for opening issues as of android 11: https://github.com/flutter/flutter/issues/90099

Solution 6 :

Two things that helped me:
Phone number should be pure number.
Country code should be the prefix with + sign.

READ  [ANSWERED] android - How to fetching current month and year data from firebase in kotlin
Powered by Inline Related Posts

Like +14564564562

Problem :

I am using this dependency url_launcher: ^5.4.1 in my project to launch whatsapp through my flutter application but when i am pressing button to launch application it is not working but showing an error message on emulator that could not open the link.
given below is the code with function i am using to launch whatsapp.

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';


void main() => runApp(Wapp());

class Wapp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
          primarySwatch: Colors.orange,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
 void launchWhatsApp(
    {@required int phone,
    @required String message,
    }) async {
  String url() {
    if (Platform.isAndroid) {
      return "whatsapp://wa.me/$phone:03452121308:/?text=${Uri.parse(message)}";
    } else {
      return "whatsapp://send?   phone=$phone&text=${Uri.parse(message)}";
    }
  }

  if (await canLaunch(url())) {
    await launch(url());
  } else {
    throw 'Could not launch ${url()}';
  }
}


Widget build(BuildContext context){
  return Scaffold(
    appBar: AppBar(
      title: Text("Home"), 
    ),

  body: Center(
    child: RaisedButton(
      
      color: Colors.orange,
      textColor: Colors.black,
      padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 60.0),
      highlightColor: Colors.green,
      onPressed: () {
        launchWhatsApp(phone: 03452121308, message: 'Hello');
      },
      child: Text("Place Your Order",style: TextStyle(
          
          fontWeight: FontWeight.bold,
          fontSize: 15
          
        )
      )
    )
  )

  );
}

}

Comments

Comment posted by Moiz Khalil

Still not working after adding https it is showing site can’t be reach. Moreover i want to launch application not website

Comment posted by void

If you are trying to send a message, consider using: the url

Comment posted by Moiz Khalil

yes it is now working but how will i open chat with specifi contact

Comment posted by void

The code above opens a specific contact as long as you give it a correct phone. @MoizKhalil. I have no idea what else you are asking for.

READ  [ANSWERED] kotlin - Room insert into one-to-many relationship
Powered by Inline Related Posts

Comment posted by Tuhin

@void

Comment posted by 7uc1f3r

Please don’t post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress