Closed CodeWizrd001 closed 4 years ago
I will need more information to help you. Could you:
debugPrint(subscriptionId, code)
before you invoke makeRequest
, and paste the output here.makeRequest
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 ?
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();
},
),
);
}
}
Ok thanks. Can you also let me know what happens when you:
*#06#
It doesn't wait for the call button
It opens up a popup with the IMEI number of the phone immediately when # is pressed
ok and what is the output of the request? could you paste a screenshot?
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.
Thank You
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