Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a direct PHONE CALL in Flutter

I need to make a direct Phone Call in flutter but it's just opening the Phone app dialer.
No direct phone call is made.

In fact, I also tried with url_launcher package for this task but am getting the same result.

    _launchURL() async {
    SimplePermissions.requestPermission(Permission.CallPhone)
        .then((state) async {
      if (state == PermissionStatus.authorized) {
        String a = Uri.encodeFull("#");
        String url = 'tel:*123' + a;
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    });}

Has anyone solved this before?

like image 573
Deepak Gehlot Avatar asked Dec 15 '18 14:12

Deepak Gehlot


1 Answers

Disclaimer: plugin author here.

Since Android API level 26, the method sendUssdRequest is exposed to make silent USSD requests.

I made a Flutter plugin called ussd_service to be able to easily access it from dart in a Flutter application. It can be used in the following manner:

import 'package:ussd_service/ussd_service.dart';

makeMyRequest() async {
  int subscriptionId = 1; // sim card subscription Id
  String code = "*21#"; // ussd code payload
  try {
    String ussdSuccessMessage = await UssdService.makeRequest(subscriptionId, code);
    print("succes! message: $ussdSuccessMessage");
  } on PlatformException catch (e) {
    print("error! code: ${e.code} - message: ${e.message}");
  }
};

makeMyRequest();

Hope this helps! Let me know on the Github repo's issues if you have any issue with it.

like image 105
vkammerer Avatar answered Sep 30 '22 21:09

vkammerer