USSD (Unstructured Supplementary Service Data) codes are short codes such as *123# that can be dialed to access various mobile network services directly from an Android device. Android apps can execute USSD codes using specific APIs like the TelephonyManager.sendUssdRequest() method, which allows developers to send USSD requests and process network responses using the TelephonyManager.UssdResponseCallback interface for handling both success and failure scenarios[3].
A typical workflow involves:
- Requesting the necessary permissions, such as
CALL_PHONE, in the app manifest to perform USSD operations[5]. - Creating a response callback class (e.g., inheriting from
TelephonyManager.UssdResponseCallback) to process responses. Implement theonReceiveUssdResponse()method for successful requests andonReceiveUssdResponseFailed()for failures[1][3]. - Using
TelephonyManager.sendUssdRequest()with the desired USSD string (like*123#) and the callback instance to initiate USSD communication[1][3]. - Processing the response, which is returned as unstructured text determined by the mobile network operator. The response can be displayed to users or used in further app logic[3].
Several open-source projects, such as USSDRunner and ussd_advanced, provide simplified implementations and wrappers for running USSD codes from within Android applications[4][5].
Older Android implementations used Intent-based approaches for USSD messaging, such as Intent.ACTION_USSD_RESPONSE, but recent Android APIs favor direct use of TelephonyManager methods[2].
Leave a Reply