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

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

最佳答案 首先要确保添加发送短信的权限

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