簡體   English   中英

SMSManager不適用於Samsung Galaxy S3 LTE

[英]SMSManager not working on Samsung 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 and 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();
      }

您錯過了致電 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);

您可以嘗試使用此庫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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM