The dialer is not showing full ussd code eg: *123*1#

只愿长相守 提交于 2019-12-02 04:03:41

问题


I am using the url_launcher plugin for call, but the dialer is not showing the # character:

String url = 'tel:*123#';
if (await canLaunch(url)) {
    await launch(url);
} else {
    throw 'Could not launch $url';
}

回答1:


You need to use URL encoding for special character in a URL.

So # equals %23

This will work launch('tel:\*123\%23');

Other Way is to encode the number typed by user and pass it through Uri.encodeFull(urlString) or Uri.encodeComponent(urlString)

Like this.

launch("tel:" + Uri.encodeComponent('*123#'));



回答2:


Disclaimer: plugin author here.

Do you want the phone call user interface to open or would you rather make the request silently? If you prefer to do it without popping the phone call UI, Android introduced in API level 26 the method sendUssdRequest.

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.



来源:https://stackoverflow.com/questions/53863850/the-dialer-is-not-showing-full-ussd-code-eg-1231

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!