vkammerer / ussd_service

A Flutter plugin to make USSD requests
https://pub.dev/packages/ussd_service
BSD 2-Clause "Simplified" License
21 stars 14 forks source link

Can't Run USSD #7

Closed CodeWizrd001 closed 4 years ago

CodeWizrd001 commented 4 years ago

Exception has occurred. PlatformException (PlatformException(ussd_plugin_ussd_execution_failure, com.vincentkammerer.ussd_service.UssdServicePlugin$RequestExecutionException, null))

Works fine for USSD codes

But fails for MMI codes

vkammerer commented 4 years ago

I will need more information to help you. Could you:

CodeWizrd001 commented 4 years ago

debugPrint shows

I/flutter ( 7776): 2, *123# for *123# and this works fine

I/flutter ( 7776): 2, *#06# for *#06#and this throws an exception

Could It Be because MMI codes work different from USSD ?

CodeWizrd001 commented 4 years ago
import 'package:android_multiple_identifier/android_multiple_identifier.dart';
import 'package:device_info/device_info.dart';
import 'package:flt_telephony_info/flt_telephony_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sim_service/models/sim_data.dart';
import 'package:ussd_service/ussd_service.dart';
import 'package:sim_service/sim_service.dart' ;
import 'package:permission_handler/permission_handler.dart' ;

class USSD extends StatefulWidget {
  @override
  _USSDState createState() => _USSDState();
}

class _USSDState extends State<USSD> {
  makeMyRequest(String code) async {
    SimData data = await SimService.getSimData ;
    int subscriptionId = data.cards.first.subscriptionId;
    PermissionStatus perStat = await Permission.phone.status ;
    if(!(perStat==PermissionStatus.granted))
      perStat = await Permission.phone.request() ;
    try {
      debugPrint("$subscriptionId, $code") ;
      String ussdSuccessMessage =
          await UssdService.makeRequest(subscriptionId, code);
      print("succes! message: $ussdSuccessMessage");
    } on PlatformException catch (e) {
      print("error! code: ${e.code} - message: ${e.message}");
    }
    return true ;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FutureBuilder(
        future: makeMyRequest("*#06#"),
        builder: (context, snapshot) {
          print(snapshot.connectionState);
          if (snapshot.connectionState == ConnectionState.done &&
              snapshot.hasData)
            return Text("Hello World");
          else
            return CircularProgressIndicator();
        },
      ),
    );
  }
}
vkammerer commented 4 years ago

Ok thanks. Can you also let me know what happens when you:

CodeWizrd001 commented 4 years ago

It doesn't wait for the call button

It opens up a popup with the IMEI number of the phone immediately when # is pressed

vkammerer commented 4 years ago

ok and what is the output of the request? could you paste a screenshot?

vkammerer commented 4 years ago

oh sorry I hadn't completely read your previous response.

Indeed this code is not a USSD request but rather executes an MMI code, which is not what Android's sendUssdRequest supports.

You can look at the differences between USSD and MMI here: https://berlin.ccc.de/~tobias/mmi-ussd-ss-codes-explained.html

If you wish to retrieve the IMEI number of the phone of the user, I suggest you use another more standard method with another Flutter plugin.

CodeWizrd001 commented 4 years ago

Thank You