I have a working function to launch sms using url_launcher
launchsms(BuildContext context, String phoneNumber) async {
try {
if (Platform.isAndroid) {
String smsuri = 'sms:$phoneNumber?body=${Uri.encodeComponent("Hello there")}';
String calluri = 'tel://$phoneNumber';
await launchUrl(Uri.parse(calluri));
} else if (Platform.isIOS) {
String smsuri = 'sms:$phoneNumber&body=${Uri.encodeComponent("Hello there")}';
await launchUrl(Uri.parse(smsuri));
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Some error occurred. Please try again!'),
),
);
}
}
I want to launch pretext sms without phone number, so that user has to select a contact or enter phone number. Is it possible?
For Android:
final String smsUri = 'sms:?body=${Uri.encodeComponent("Hello there")}';
For iOS:
final String smsUri = 'sms:?&body=${Uri.encodeComponent("Hello there")}';
//For iOS, please check this in real device. I have tried this in simulator and user can select phone numbers also, but the selected phone numbers are not showing on message screen only loading.