简体   繁体   中英

How to open whatssap app from my flutter-android app

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")));
  }
}

} }

在此处输入图像描述

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

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

https://pub.dev/packages/flutter_appavailability

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM