SMSManager无法在三星Galaxy S3 LTE上运行

时间:2013-08-22 10:14:20

标签: android galaxy smsmanager

我创建了简单的代码来发送正在使用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);

3 个答案:

答案 0 :(得分:2)

首先确保添加发送短信的权限

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

然后用try和catch包围你的代码以找到阻止发送三星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();
      }

答案 1 :(得分: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);

答案 2 :(得分: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);