Pergunta

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);
Foi útil?

Solução

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();
      }

Outras dicas

You have missed to call PendingIntent deliveredPI

Try this code..!!

PendingIntent sentPI =PendingIntent.getBroadcast(activity, 0,new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,new Intent(DELIVERED), 0);
sms.sendTextMessage("01234567890", null, msg, sentPI, deliveredPI);

You can try using this library android-smsmms to send SMS

Settings sendSettings = new Settings();
sendSettings.setDeliveryReports(true);
sendSettings.setSplit(true);
Message mMessage = new Message(textToSend, addressToSendTo);.
sendTransaction.sendNewMessage(message, null)

Hope this helps you

EDIT

com.klinker.android.send_message.Settings sendSettings = new com.klinker.android.send_message.Settings();
sendSettings.setDeliveryReports(true);
sendSettings.setSplit(true);
sendSettings.setSplitCounter(true);
sendSettings.setStripUnicode(true);
com.klinker.android.send_message.Transaction sendTransaction = new com.klinker.android.send_message.Transaction(getApplicationContext(), sendSettings);
com.klinker.android.send_message.Message mMessage = new com.klinker.android.send_message.Message("Message", "9999999999");
sendTransaction.sendNewMessage(mMessage, 0);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top