Search code examples
androidgalaxysmsmanager

SMSManager not working on Samsung Galaxy S3 LTE


I created simple code to send SMS which is working on Xperia U and QMobile (local brand). But it is not working on Samsung Galaxy S3 LTE

They code is

import android.telephony.SmsManager;
SmsManager sms = SmsManager.getDefault();
            PendingIntent sentPI;
            String SENT = "SMS_SENT";

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

            sms.sendTextMessage("01234567890", null, msg, sentPI, null);

Solution

  • first be sure to add the permission to send SMSs

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

    and then surround your code with try and catch to find the error that prevents sending in Samsung s3 lte ..

          try {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage("01234567890", null, msg, sentPI, null);
            Toast.makeText(getApplicationContext(), "SMS Sent!",
                        Toast.LENGTH_LONG).show();
          } catch (Exception e) {
            Toast.makeText(getApplicationContext(),
                "SMS faild, please try again later!",
                Toast.LENGTH_LONG).show();
            e.printStackTrace();
          }