Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESULT_ERROR_GENERIC_FAILURE return while sending sms using Sms Manager in android

I am using Sms Manager to sent sms to multiple users but i am getting RESULT_ERROR_GENERIC_FAILURE (Generic failure) .how to resolve this issue?

// ---sends an SMS message to another device---
private void sendSMS(String phoneNumber, String message) {
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
            SENT), 0);

    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

    // ---when the SMS has been sent---
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS sent",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                Toast.makeText(getBaseContext(), "Generic failure",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                Toast.makeText(getBaseContext(), "No service",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                Toast.makeText(getBaseContext(), "Null PDU",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Toast.makeText(getBaseContext(), "Radio off",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    }, new IntentFilter(SENT));

    // ---when the SMS has been delivered---
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            case Activity.RESULT_CANCELED:
                Toast.makeText(getBaseContext(), "SMS not delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    }, new IntentFilter(DELIVERED));

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}

Here i am using SmsManager and sendSms() taken number and message as parameters.

like image 252
Android Surya Avatar asked Jan 31 '14 10:01

Android Surya


People also ask

How can solve generic failure in sending SMS?

One of the most common errors encountered using the Telerivet Gateway app is the "generic failure" while sending messages. This usually means that your Android phone does not have sufficient credit with your mobile network. Make sure that your Android phone has enough credit to send SMS messages and try again.

What is SmsManager in android?

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) .


1 Answers

May be you should shorten your SMS body to fit in only 1 sms (which is only 160 charachters), I used the same code & got the exact same error & when I shortened the sms under 160, it was sent successfully :)

like image 98
AbdelHady Avatar answered Sep 18 '22 13:09

AbdelHady