ussd reader in Recket Native module

I have this code that opens a window for a phone I want when it doesn't open that window and send me the result send ussd to fronend in react native

class UssdModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {

    override fun getName(): String {
        return "UssdModule"
    }

    @ReactMethod
    fun openUssdDialog(ussdCode: String) {
        val encodedUssdCode = Uri.encode(ussdCode)
        val intent = Intent(Intent.ACTION_CALL, Uri.parse("tel:$encodedUssdCode"))
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        currentActivity?.startActivity(intent)
    }
}

Upvotes: 0

Views: 71

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93708

Edited from original answer: It turns out they added support in Android 26 to make a USSD call. The function is TelephonyManager.sendUssdRequest. It does not exist on devices older than 26. And what ussd commands are supported is not specified, I would only rely on the bare basics and not advanced menu functionality.

Still if you have any other way of getting that information use that instead. In reality- USSD is kind of a dead technology. It existed in pre-data days to provide limited ability to make network calls. In the modern day when every phone has data there's no advantage to using it over a web service. Remember that USSD codes vary by OEM, carrier, etc- they are not universal. So by using any USSD code at all you are limiting your app to working on only a subset of phones most likely by a specific OEM or carrier. Expect to have a low Play Store rating because you'll be given 1 stars by everyone without that model/carrier who downloads your app.

Upvotes: 0

Related Questions