4

我创建了简单的代码来发送适用于 Xperia U 和 QMobile(本地品牌)的 SMS。但它不适用于三星 Galaxy S3 LTE

他们的代码是

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);
4

3 回答 3

2

首先一定要添加发送短信的权限

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

然后用 try 和 catch 包围您的代码以查找阻止在 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();
      }
于 2013-08-26T10:06:47.827 回答
0

你错过了来电 PendingIntent deliveredPI

试试这个代码..!!

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);
于 2013-09-02T06:12:02.817 回答
0

你可以尝试使用这个库android-smsmms来发送短信

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

希望这可以帮助你

编辑

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);
于 2013-09-02T08:52:58.597 回答