I’m working on a Flutter app and need your help to improve the handling of WhatsApp links. Currently, when I click on a phone number, a bottom sheet (or popup) appears asking if I want to use the dialer or WhatsApp. However, when I choose WhatsApp, it opens a page in the browser and then (on some devices, but not on others) an Android popup that lets me choose between WhatsApp and WhatsApp Business.
This behavior is inconsistent across different devices, and I want to avoid the browser step, as it might confuse less tech-savvy users (which is the majority of my app’s users).
My goal is to make it so that when I press "WhatsApp," a dialog appears directly that allows me to choose between WhatsApp and WhatsApp Business, with the option to do it "only once" or "always." I want to avoid forcing users to change their Android settings to select the default WhatsApp app.
Here’s the code I’m currently using to handle WhatsApp and that is not working as intended:
void _launchWhatsApp(String phoneNumber) async {
const whatsappBusinessScheme = 'whatsapp://send?phone=';
const whatsappScheme = 'https://wa.me/';
final Uri whatsappBusinessUri =
Uri.parse('$whatsappBusinessScheme$phoneNumber');
if (await canLaunchUrl(whatsappBusinessUri)) {
await launchUrl(whatsappBusinessUri);
} else {
final Uri whatsappUri = Uri.parse('$whatsappScheme$phoneNumber');
if (await canLaunchUrl(whatsappUri)) {
await launchUrl(whatsappUri);
} else {
Get.snackbar('error'.tr, 'whatsapp_error'.tr);
}
}
}
Do I need to add something in the AndroidManifest or info.plist? Or is there something I’m missing?
Does anyone have suggestions on how to implement this functionality without going through the browser? Any help would be greatly appreciated!
Thanks in advance!
2
Answers
I get it to work on android but i still have problems iOS side.
On android i modified the MainActivity.kt to include this
then in the phone.dart
with these mods now when i press on whatsapp button i get a dialog that ask me if i want open it through WA, or WA business .
i tried to modify swift code too, in a similar way, but it didn't work as expected. I'll keep you updated if i'll manage it to work
Use
externalApplication
mode inurl_launcher