thl_ussd_service 0.1.0 copy "thl_ussd_service: ^0.1.0" to clipboard
thl_ussd_service: ^0.1.0 copied to clipboard

A Flutter plugin to make silent USSD requests and read their responses, using Android's sendUssdRequest. iOS is not supported. Upgraded fork of ussd_service.

thl_ussd_service #

A Flutter plugin to make silent USSD requests and read their responses, using Android's native sendUssdRequest method.

This is an updated and modernized fork of the original ussd_service package, fully compatible with Dart 3, recent Flutter versions, and Android Gradle Plugin (AGP) 8.0+ / 9.0+.

Note: iOS is not supported.


Installation #

Add thl_ussd_service as a dependency in your pubspec.yaml:

dependencies:
  thl_ussd_service: ^1.0.0

Android Manifest Permissions #

Ensure that your AndroidManifest.xml (located in android/app/src/main/AndroidManifest.xml) includes the CALL_PHONE permission:

<uses-permission android:name="android.permission.CALL_PHONE" />

Usage #

Before making a USSD request with this plugin, you must:

  1. Request Permissions: Make sure the user has granted access to phone calls, for example using the permission_handler package.
  2. Retrieve Subscription ID: Retrieve the SIM card subscription ID, for example using the sim_data_plus or flutter_sim_data packages.

Example Code #

import 'package:flutter/services.dart';
import 'package:thl_ussd_service/thl_ussd_service.dart';

Future<void> makeMyRequest() async {
  int subscriptionId = 1; // Retrieve this using a SIM card data plugin
  String code = "*#21#";   // Your USSD code
  
  try {
    String ussdResponseMessage = await UssdService.makeRequest(
      subscriptionId,
      code,
      const Duration(seconds: 10), // Optional timeout - default is 10 seconds
    );
    print("Success! Response message: $ussdResponseMessage");
  } on PlatformException catch (e) {
    print("Execution failed! Code: ${e.code} - Message: ${e.message}");
  }
}

Interactive / Multi-step USSD Sessions #

Android's native sendUssdRequest API does not support interactive or multi-step USSD sessions (where you input options in menus). Consequently, this plugin does not support them either.

However, many mobile carriers allow you to perform multi-step operations by appending options directly within a single request using the format:

*firstCode*secondOption*thirdOption#

For example: *123*1*2# instead of dialing *123#, waiting for a menu, entering 1, and then entering 2.

1
likes
0
points
250
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to make silent USSD requests and read their responses, using Android's sendUssdRequest. iOS is not supported. Upgraded fork of ussd_service.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on thl_ussd_service

Packages that implement thl_ussd_service