Merge pull request #1725 from Lexsus/fix_big_sms_bg

fix error with big sms text in UTF-8
This commit is contained in:
Milos Kozak 2019-04-09 15:41:43 +02:00 committed by GitHub
commit 9ca179ec14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -760,11 +760,18 @@ 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);
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);