From 23a9adc062c58198eae18ec14a609cfa0d882250 Mon Sep 17 00:00:00 2001 From: untidylamp <44341286+untidylamp@users.noreply.github.com> Date: Sun, 21 Oct 2018 10:24:52 -0400 Subject: [PATCH 1/5] Long sms support fix for bug SMS gets cut up into many messages #15 Thanks to https://github.com/vovs/gtalksms/blob/master/src/com/googlecode/gtalksms/receivers/SmsReceiver.java --- .../droogers/smsmatrix/ReceiverListener.java | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/droogers/smsmatrix/ReceiverListener.java b/app/src/main/java/eu/droogers/smsmatrix/ReceiverListener.java index db19e36..cf1e6c0 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/ReceiverListener.java +++ b/app/src/main/java/eu/droogers/smsmatrix/ReceiverListener.java @@ -7,6 +7,8 @@ import android.os.Bundle; import android.telephony.SmsMessage; import android.telephony.TelephonyManager; import android.util.Log; +import java.util.HashMap; +import java.util.Map; /** * Created by gerben on 6-10-17. @@ -25,23 +27,41 @@ public class ReceiverListener extends BroadcastReceiver { } private void handleIncomingSMS(Context context, Intent intent) { - Bundle bundle = intent.getExtras(); + Map msg = null; SmsMessage[] msgs = null; - String msg_from; - if (bundle != null){ - try{ - Object[] pdus = (Object[]) bundle.get("pdus"); - msgs = new SmsMessage[pdus.length]; - for(int i=0; i(nbrOfpdus); + msgs = new SmsMessage[nbrOfpdus]; + + // Send long SMS of same sender in one message + for (int i = 0; i < nbrOfpdus; i++) { msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); - msg_from = msgs[i].getOriginatingAddress(); - String msgBody = msgs[i].getMessageBody(); - Utilities.sendMatrix(context, msgBody, msg_from, Matrix.MESSAGE_TYPE_TEXT); + + String originatinAddress = msgs[i].getOriginatingAddress(); + + // Check if index with number exists + if (!msg.containsKey(originatinAddress)) { + // Index with number doesn't exist + msg.put(msgs[i].getOriginatingAddress(), msgs[i].getMessageBody()); + + } else { + // Number is there. + String previousparts = msg.get(originatinAddress); + String msgString = previousparts + msgs[i].getMessageBody(); + msg.put(originatinAddress, msgString); + } } - }catch(Exception e){ - Log.d("Exception caught",e.getMessage()); } } + for (String originatinAddress : msg.keySet()) { + Utilities.sendMatrix(context, msg.get(originatinAddress), originatinAddress, Matrix.MESSAGE_TYPE_TEXT); + } } private void handleIncomingCall(Context context, Intent intent) { From 6ec3dc538155adaf8524ad4c6b465c5e5fa65583 Mon Sep 17 00:00:00 2001 From: untidylamp <44341286+untidylamp@users.noreply.github.com> Date: Sun, 21 Oct 2018 10:39:10 -0400 Subject: [PATCH 2/5] Dont start the service when the app is open --- app/src/main/java/eu/droogers/smsmatrix/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java index 8f1ff99..e1c3513 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java +++ b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java @@ -68,7 +68,7 @@ public class MainActivity extends Activity { startService(); } }); - startService(); + checkPermissions() } private void checkPermissions() { From f87339668d0267e18770766c9a3000efa8cf2812 Mon Sep 17 00:00:00 2001 From: untidylamp <44341286+untidylamp@users.noreply.github.com> Date: Sun, 21 Oct 2018 10:39:33 -0400 Subject: [PATCH 3/5] Update MainActivity.java --- app/src/main/java/eu/droogers/smsmatrix/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java index e1c3513..78379f0 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java +++ b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java @@ -68,7 +68,7 @@ public class MainActivity extends Activity { startService(); } }); - checkPermissions() + checkPermissions(); } private void checkPermissions() { From 914148c10077e95efad0777dd2609ab79bb26df9 Mon Sep 17 00:00:00 2001 From: untidylamp <44341286+untidylamp@users.noreply.github.com> Date: Sun, 21 Oct 2018 10:41:59 -0400 Subject: [PATCH 4/5] Toast if missing information --- app/src/main/java/eu/droogers/smsmatrix/MatrixService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java b/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java index f08aa0c..1102561 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java +++ b/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java @@ -43,8 +43,10 @@ public class MatrixService extends Service { if (mx == null && !botUsername.isEmpty() && !botPassword.isEmpty() && !username.isEmpty() && !device.isEmpty() && !hsUrl.isEmpty() && !syncDelay.isEmpty() && !syncTimeout.isEmpty()) { mx = new Matrix(getApplication(), hsUrl, botUsername, botPassword, username, device, syncDelay, syncTimeout); - Log.e(TAG, "onStartCommand222: " + hsUrl ); + Log.e(TAG, "onStartCommand: " + hsUrl ); Toast.makeText(this, "service starting:", Toast.LENGTH_SHORT).show(); + } else if (mx == null) { + Toast.makeText(this, "Missing Information", Toast.LENGTH_SHORT).show(); } Log.e(TAG, "onStartCommand: Service"); From 97746625c4aba274f62c491283dc53ee01116439 Mon Sep 17 00:00:00 2001 From: untidylamp_gitlab <44341286+untidylamp@users.noreply.github.com> Date: Thu, 1 Nov 2018 16:34:55 -0400 Subject: [PATCH 5/5] allways have the service running --- app/src/main/java/eu/droogers/smsmatrix/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java index 78379f0..8f1ff99 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java +++ b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java @@ -68,7 +68,7 @@ public class MainActivity extends Activity { startService(); } }); - checkPermissions(); + startService(); } private void checkPermissions() {