'Multipart in Receiver SMS
I have developed a program to send normal and encrypted SMS where I am trying to send long messages, more than 160 characters but; in the Receiver it is not receiving it right.
This is the logic of a normal message (short msgs <= 160 characters and long msgs > 160 characters).
builder.setNegativeButton("Normal", new DialogInterface.OnClickListener() {
largoMsg = sendingMsg.length();
int position = 0;
for (int j = 0; j < ctdmsg; j++) {
if (largoMsg > 160) {
mensaje = sendingMsg.substring(position, (j + 1) * 160);
position = (j + 1) * 160;
largoMsg = largoMsg - 160;
} else {
mensaje = sendingMsg.substring(position);
}
SendSMS(mensaje);
}
dialog.cancel();
});
[And this is the image of the sent1
And this is the Receive part:
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(MySMSMonitor.SMS_RECEIVED_ACTION)) {
Bundle extras = intent.getExtras();
SmsMessage[] messages = null;
infoSender = "";
infoSMS = "";
String phoneSender = "";
if (extras != null) {
// Retrieve the sms message received
Object[] pdus = (Object[]) extras.get("pdus");
messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
phoneSender = messages[0].getOriginatingAddress();
phoneSender = PhoneNumberUtils.formatNumber(phoneSender, "JM");
infoSender += messages[i].getOriginatingAddress();
if (messages.length > 1)
infoSender = phoneSender;
infoSMS += messages[i].getMessageBody().toString();
creaDataReceiver();
}
MsgToats("!SMS recibido !!!");
retrieveMensajes();
refreshDisplay();
Bundle bolsa = new Bundle();
bolsa.putString("TLF", miTelefono);
bolsa.putString("DUMMY", dummy);
bolsa.putString("ADDRESS", infoSender);
Intent intentnotify = new Intent(CipherActivity.this, NotificacionSms.class);
intentnotify.putExtras(bolsa);
startActivity(intentnotify);
}
}
}
And this is the image of the one who receives
Short messages work fine for me with multiple destinations but; I can't get long messages to be well received.
Please I need help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
