diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.java index ca80ea1cf5..f8afafca75 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.java @@ -31,14 +31,14 @@ public class ActionSendSMS extends Action { @Override public String shortDescription() { - return MainApp.gs(R.string.sendsmsactionlabel); + return MainApp.gs(R.string.sendsmsactionlabel, text.getValue()); } @Override public void doAction(Callback callback) { - SmsCommunicatorPlugin.getPlugin().sendNotificationToAllNumbers(text.getValue()); + boolean result = SmsCommunicatorPlugin.getPlugin().sendNotificationToAllNumbers(text.getValue()); if (callback != null) - callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run(); + callback.result(new PumpEnactResult().success(result).comment(result ? R.string.ok : R.string.danar_error)).run(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java index 6e8b07499a..28b0abd33d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java @@ -33,11 +33,12 @@ public class Notification { public static final int OLD_NSCLIENT = 8; public static final int OLD_NS = 9; public static final int INVALID_PHONE_NUMBER = 10; - public static final int APPROACHING_DAILY_LIMIT = 11; - public static final int NSCLIENT_NO_WRITE_PERMISSION = 12; - public static final int MISSING_SMS_PERMISSION = 13; - public static final int PUMPERROR = 14; - public static final int WRONGSERIALNUMBER = 15; + public static final int INVALID_MESSAGE_BODY = 11; + public static final int APPROACHING_DAILY_LIMIT = 12; + public static final int NSCLIENT_NO_WRITE_PERMISSION = 13; + public static final int MISSING_SMS_PERMISSION = 14; + public static final int PUMPERROR = 15; + public static final int WRONGSERIALNUMBER = 16; public static final int NSANNOUNCEMENT = 18; public static final int NSALARM = 19; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java index 1304c00eb6..d1494e6033 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java @@ -737,11 +737,13 @@ public class SmsCommunicatorPlugin extends PluginBase { sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat)); } - public void sendNotificationToAllNumbers(String text) { + public boolean sendNotificationToAllNumbers(String text) { + boolean result = true; for (int i = 0; i < allowedNumbers.size(); i++) { Sms sms = new Sms(allowedNumbers.get(i), text); - sendSMS(sms); + result = result && sendSMS(sms); } + return result; } private void sendSMSToAllNumbers(Sms sms) { @@ -751,7 +753,7 @@ public class SmsCommunicatorPlugin extends PluginBase { } } - void sendSMS(Sms sms) { + boolean sendSMS(Sms sms) { SmsManager smsManager = SmsManager.getDefault(); sms.text = stripAccents(sms.text); @@ -768,13 +770,22 @@ public class SmsCommunicatorPlugin extends PluginBase { messages.add(sms); } catch (IllegalArgumentException e) { - Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL); - RxBus.INSTANCE.send(new EventNewNotification(notification)); + if (e.getMessage().equals("Invalid message body")) { + Notification notification = new Notification(Notification.INVALID_MESSAGE_BODY, MainApp.gs(R.string.smscommunicator_messagebody), Notification.NORMAL); + RxBus.INSTANCE.send(new EventNewNotification(notification)); + return false; + } else { + Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL); + RxBus.INSTANCE.send(new EventNewNotification(notification)); + return false; + } } catch (java.lang.SecurityException e) { Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL); RxBus.INSTANCE.send(new EventNewNotification(notification)); + return false; } MainApp.bus().post(new EventSmsCommunicatorUpdateGui()); + return true; } private String generatePasscode() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96be1ed021..5d60cee294 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1574,7 +1574,7 @@ Set Bolus Change profile to Change profile to %1$s - Send SMS + Send SMS: %1$s Send SMS to all numbers in preferences Send SMS with text @@ -1594,5 +1594,6 @@ Close Increasing max basal value because setting is lower than your max basal in profile + Invalid message body