As on 13th August 2022, these are the latest updates :
This will work for Calls, SMS, Emails and Websites
Step 1:
Go to pubspec.yaml under Project
pubspec.yaml
and paste url_launcher : ^6.1.5 under dependencies:
( Click on https://pub.dev/packages/url_launcher to get the latest version)
> dependencies:
flutter:
> sdk: flutter
>
> url_launcher: ^6.1.5
Then Run -
Pub Get
Go to AndroidManifest.xml under android/app/src/main/AndroidManifest.xml
AndroidManifest.xml
And paste the following codes for Phone calls, Sms, Email and Website under package="com.example......" like so -
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codoweb.your project name">
<!-- Provide required visibility configuration for API level 30 and above -->
<queries>
<!-- If your app opens https URLs -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<!-- If your app sends emails -->
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
<!-- If your app checks for SMS support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<!-- If your app checks for call support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
</queries>
Now use the following codes for activating :
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Debasis Sil Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.black,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
centerTitle: true,
title: Text('Debasis Sil Flutter Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
final web = Uri.parse(
'https://codoweb.com/',
);
if (await canLaunchUrl(web)) {
launchUrl(web);
} else {
throw 'Could not launch $web';
}
},
child: const Text('Web'),
),
ElevatedButton(
onPressed: () async {
final email = Uri(
scheme: 'mailto',
path: 'codoweb.tech@gmail.com',
query: 'subject=Hello&body=Test',
);
if (await canLaunchUrl(email)) {
launchUrl(email);
} else {
throw 'Could not launch $email';
}
},
child: const Text('Email'),
),
ElevatedButton(
onPressed: () async {
final call = Uri.parse('tel:+91 9830268966');
if (await canLaunchUrl(call)) {
launchUrl(call);
} else {
throw 'Could not launch $call';
}
},
child: const Text('Call'),
),
ElevatedButton(
onPressed: () async {
final sms = Uri.parse('sms:5550101234');
if (await canLaunchUrl(sms)) {
launchUrl(sms);
} else {
throw 'Could not launch $sms';
}
},
child: const Text('SMS'),
),
],
),
),
);
}
}
And Bingo! You are good to go...
Hope this helps :)
I found this motivating that helped me resolve my issue.
Please check :
https://dev-yakuza.posstree.com/en/flutter/url_launcher/