chmduquesne / talkmyphone

Automatically exported from code.google.com/p/talkmyphone
0 stars 0 forks source link

[Fixed in GTalkSMS] smsReceiver: Long SMS from same sender with sms:number inbetween #102

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
So, when you receive a long from someone the current code puts the annoying 
sms:+49123127483: between the parts.

This can be fixed e.g. by using an associative array indexed by sender number 
for storing all SMS prior to sending via XMPP. This also takes care of the case 
when a SMS from a different sender is received between the parts of the same 
sender. Maybe you can use the code, it's not too pretty yet.

public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;

    if (bundle != null)  {
        XmppService service = XmppService.getInstance();
        if (service != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");                
            int nbrOfpdus = pdus.length;
            msgs = new SmsMessage[nbrOfpdus];

            // There can be multiple SMS from multiple senders, there can be a maximum of nbrOfpdus different senders
            // However, send long SMS of same sender in one message
            ArrayList<String> sndr = new ArrayList<String>();
            Map<String, String> msg = new HashMap<String, String>();

            for (int i = 0; i < nbrOfpdus; i++) {
                msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);

                String msgString = msg.get(msgs[i].getOriginatingAddress()); // Check if index with number exists

                if(msgString == null) { // Index with number doesn't exist                                               
                    sndr.add(msgs[i].getOriginatingAddress());  // Save sender for accessing associative array later

                    StringBuilder builder = new StringBuilder();    // Build string  
                    builder.append("sms:");
                    builder.append(msgs[i].getOriginatingAddress());
                    builder.append(":");
                    builder.append(msgs[i].getMessageBody().toString());                        

                    msg.put(msgs[i].getOriginatingAddress(), builder.toString()); // Save string into associative array with sendernumber as index

                } else {    // Number has been there, add content
                    // msgString already contains sms:sndrNbr:previousparts of SMS, just add this part
                    msgString = msgString + msgs[i].getMessageBody().toString();
                    msg.put(msgs[i].getOriginatingAddress(), msgString);
                }
            }

            // Finally, send all SMS via XMPP by sender
            for(int i = 0; i < sndr.size(); i++) {
                service.send(msg.get(sndr.get(i)));
            }

        }
    }
}

Original issue reported on code.google.com by valentin...@gtempaccount.com on 15 Oct 2010 at 8:39

GoogleCodeExporter commented 9 years ago
Hi,

Please put your changes in a public clone. Applying patches by hand is a real 
pain...

Thank you for your contribution!

Original comment by chm.duquesne on 15 Oct 2010 at 8:49

GoogleCodeExporter commented 9 years ago
Fix with valentin@quelltextfabrik.de solution

The project has migrate at http://code.google.com/p/gtalksms

Original comment by Florent....@gmail.com on 11 Dec 2010 at 11:50

GoogleCodeExporter commented 9 years ago

Original comment by Florent....@gmail.com on 11 Dec 2010 at 11:51