When I send an SMS using SmsManager
, the result intent broadcasted holds a value of 5
Activity.RESULT_OK
SmsManager.RESULT_ERROR_GENERIC_FAILURE
SmsManager.RESULT_ERROR_NO_SERVICE
SmsManager.RESULT_ERROR_NULL_PDU
SmsManager.RESULT_ERROR_RADIO_OFF
What's meant by every one of them? and please mention a test case that could generate each one. I know that RESULT_OK denotes a successfully sent SMS. GENERIC_FAILURE occurs for general erros (e.g. I've no credit).
But I've activated Airplane mode and tried to send an SMS. I've thought it would trigger NO_SERVICE error, but a RADIO_OFF was triggered instead. Also the official documentation is not demonstrating them very well.
↳ android.telephony.SmsManager. Manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method getDefault() . To create an instance of SmsManager associated with a specific subscription ID, call getSmsManagerForSubscriptionId(int) .
Before starting your application, Android studio installer will display following window to select an option where you want to run your Android application. Now you can enter a desired mobile number and a text message to be sent on that number. Finally click on Send SMS button to send your SMS.
Here's my comments on the documentation of SmsManager:
RESULT_ERROR_GENERIC_FAILURE
: Generic failure cause
Something went wrong and there's no way to tell what, why or how.
RESULT_ERROR_NO_SERVICE
: Failed because service is currently unavailable
Your device simply has no cell reception. You're probably in the middle of nowhere, somewhere inside, underground, or up in space. Certainly away from any cell phone tower.
RESULT_ERROR_NULL_PDU
: Failed because no pdu provided
Something went wrong in the SMS stack, while doing something with a protocol description unit (PDU) (most likely putting it together for transmission).
RESULT_ERROR_RADIO_OFF
: Failed because radio was explicitly turned off
You switched your device into airplane mode, which tells your device exactly "turn all radios off" (cell, wifi, Bluetooth, NFC, ...).
In the end, most apps need not care why sending an SMS failed (except ask the user if airplane mode is on in case of RESULT_ERROR_RADIO_OFF
), because there's nothing the app itself can do to remedy it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With