fix error with big sms text in UTF-8

This commit is contained in:
Lexsus 2019-04-08 15:23:40 +03:00
parent c2cf6d1000
commit b9056384f9

View file

@ -760,11 +760,19 @@ public class SmsCommunicatorPlugin extends PluginBase {
void sendSMS(Sms sms) {
SmsManager smsManager = SmsManager.getDefault();
sms.text = stripAccents(sms.text);
if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
try {
if (L.isEnabled(L.SMS))
log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text);
smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
if (sms.text.getBytes().length<=140)
smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
else
{
ArrayList<String> parts = smsManager.divideMessage(sms.text);
smsManager.sendMultipartTextMessage(sms.phoneNumber, null, parts,
null, null);
}
messages.add(sms);
} catch (IllegalArgumentException e) {
Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL);