This plugin makes it possible to access Android's sendUssdRequest method from a Flutter application.
Add ussd_service
as a dependency in your pubspec.yaml.
Make sure that your AndroidManifext.xml
file includes the following permission:
<uses-permission android:name="android.permission.CALL_PHONE" />
Before you use this plugin, you must:
- make sure that the user has authorized access to his phone calls, for example with the permission_handler plugin.
- retrieve the SIM card subscription ID, for example with the sim_data plugin.
You may then use the plugin:
import 'package:ussd_service/ussd_service.dart';
makeMyRequest() async {
int subscriptionId = 1; // sim card subscription ID
String code = "*#21#"; // ussd code payload
try {
String ussdResponseMessage = await UssdService.makeRequest(
subscriptionId,
code,
Duration(seconds: 10), // timeout (optional) - default is 10 seconds
);
print("succes! message: $ussdResponseMessage");
} catch(e) {
debugPrint("error! code: ${e.code} - message: ${e.message}");
}
};
void main() => makeMyRequest();
Android's sendUssdRequest doesn't support interactive / multi steps USSD sessions, so this plugin doesn't support them either. However, as mentioned by a user who reported it in a comment, you may be able to achieve similar behaviour by passing all arguments in a single USSD request.
*firstCode*2ndCode*3rdCode*4thCode*..*..#