mirror of
https://github.com/tijder/SmsMatrix.git
synced 2024-10-27 18:24:01 +00:00
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
This commit is contained in:
parent
4efdf09f7b
commit
23a9adc062
@ -7,6 +7,8 @@ import android.os.Bundle;
|
|||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by gerben on 6-10-17.
|
* Created by gerben on 6-10-17.
|
||||||
@ -25,23 +27,41 @@ public class ReceiverListener extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleIncomingSMS(Context context, Intent intent) {
|
private void handleIncomingSMS(Context context, Intent intent) {
|
||||||
Bundle bundle = intent.getExtras();
|
Map<String, String> msg = null;
|
||||||
SmsMessage[] msgs = null;
|
SmsMessage[] msgs = null;
|
||||||
String msg_from;
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundle != null){
|
|
||||||
try{
|
if (bundle != null && bundle.containsKey("pdus")) {
|
||||||
Object[] pdus = (Object[]) bundle.get("pdus");
|
Object[] pdus = (Object[]) bundle.get("pdus");
|
||||||
msgs = new SmsMessage[pdus.length];
|
|
||||||
for(int i=0; i<msgs.length; i++){
|
if (pdus != null) {
|
||||||
|
int nbrOfpdus = pdus.length;
|
||||||
|
msg = new HashMap<String, String>(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]);
|
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
|
||||||
msg_from = msgs[i].getOriginatingAddress();
|
|
||||||
String msgBody = msgs[i].getMessageBody();
|
String originatinAddress = msgs[i].getOriginatingAddress();
|
||||||
Utilities.sendMatrix(context, msgBody, msg_from, Matrix.MESSAGE_TYPE_TEXT);
|
|
||||||
|
// 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) {
|
private void handleIncomingCall(Context context, Intent intent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user