使用postpaid

时间:2015-09-16 12:26:32

标签: android sms smsmanager

我在android中使用SmsManager发送消息。使用预付费号码时,此应用在我的设备上正常运行。但是当我使用后付费号码时,我无法发送消息。预付费和后付费号码对于在Android中发送消息很重要。请帮忙。

1 个答案:

答案 0 :(得分:0)

但是,我发现如果消息计数超过160,则sms.sendTextMessage()无法正常工作。即。您必须将消息分成几部分,然后分成sms.sendMultiPartTextMessage()。只有英文字符<= 160才能发送短信。如果您使用任何特殊字符,则计数(长度)应为&lt; = 70。以下是我的代码。我正在使用阿拉伯字符。

private void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(act, 0, new Intent(
        SENT), 0);

PendingIntent deliveredPI = PendingIntent.getBroadcast(act, 0,
        new Intent(DELIVERED), 0);

if (message.length() <= 70) {
    SmsManager sms = SmsManager.getDefault();
    Log.d(LOG_TAG, "Send Sms : " + message + " serverNumber "
            + phoneNumber);
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
} else {
    SmsManager sms = SmsManager.getDefault();
    ArrayList<String> parts = sms.divideMessage(message);
    int numParts = parts.size();

    ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
    ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();

    for (int i = 0; i < numParts; i++) {
        sentIntents.add(PendingIntent.getBroadcast(act, 0, new Intent(
                SENT), 0));
        deliveryIntents.add(PendingIntent.getBroadcast(act, 0,
                new Intent(DELIVERED), 0));
    }
    Log.d(LOG_TAG, "Send Sms multipart : " + message + " serverNumber "
            + phoneNumber);
    sms.sendMultipartTextMessage(phoneNumber, null, parts, sentIntents,
            deliveryIntents);
}

我希望这会有所帮助