Home > Back-end >  How to open whatssap app from my flutter-android app
How to open whatssap app from my flutter-android app

Time:08-10

I have been trying to open the whatsapp aplication from my flutter app. But it trying to opening the whatssap in my same app, instead of open the whatsapp app. And also, once it open, inmediately show my an error message. Y have tried all the possible combination that could be in internet.

 void _showWhatssap() async {

String whatsapp = ' 593963631704';   

var whatsappURlAndroid = Uri.parse('https://wa.me/$whatsapp');    
    
var whatappURLIos =
    Uri.parse('https://wa.me/$whatsapp?text=${Uri.parse("hello")}');

if (Platform.isIOS) {
  // for iOS phone only
  if (await canLaunchUrl(whatappURLIos)) {
    await launchUrl(whatappURLIos);
  } else {
    ScaffoldMessenger.of(context)
        .showSnackBar(SnackBar(content: new Text("whatsapp no installed")));
  }
}
else {
  bool status  = await canLaunchUrl(whatsappURlAndroid);
  print("ESTADO: ${status}");
  if (status) {

    await launchUrl(whatsappURlAndroid);
  } else {
    ScaffoldMessenger.of(context)
        .showSnackBar(SnackBar(content: new Text("whatsapp no installed para android")));
  }
}

} }

enter image description here

CodePudding user response:

you can use the following package to check app availability and open it.

https://pub.dev/packages/flutter_appavailability

CodePudding user response:

using url luncher https://pub.dev/packages/url_launcher make sure u Follow the Instructions cuze it's work fine with me

void _showWhatssap() async {

var whatsappUrl ="whatsapp://send?phone= 593963631704&text=hi";
await canLaunch(whatsappUrl)? launch(whatsappUrl):print("open whatsapp app link or do a snackbar with notification that there is no whatsapp installed");

} 

and u can see this https://pub.dev/packages/whatsapp_share2

and u can check this https://pub.dev/packages/flutter_launch it's for whatsapp example

  • Related