I'm trying to send a binary sms in Android. But when the size of the message exceeds one sms, I get different errors depending on the device.
I saw there is a method to send multi-part text sms, but not for sending multi part binary sms. So, what I have to do?
It seems that there's really no way to do this.
I've found someone that asked this same thing on Android Developer list two years ago and received no answers until now. Unfortunately, I'm not finding the post right now, but there are many other questions about this:
Android Developers › Sending big binary sms
Android Developers › Missing API functionallity sending binary data sms with more that 1
Android Developers › more SMS questions
The best solution I could came across was to encode the message as BASE64 and send as a multipart TEXT sms.
I hope this answer help someone looking for the same think in the future.
you can do this by data SMS, i did it and works!
you must split your data to packet limit and using :
smsManager.sendDataMessage(_phoneNumber, null, SMS_PORT,
s.getBytes(), sent, deliveredPI);
for each part.
it sends data separately and you can receive normaly :)
@amin10043 you're right but to handle splitted data message you have to do something more because receiver doesn't know how many parts of message will be. I've prepared a function which send a multipart data message and on first byte of message it placed a number of parts:
private void sendEncryptedMessage(String plainMessage) throws IOException {
Integer PDU_SIZE = 130;
EncryptedMessage encryptedMessage = new EncryptedMessage(plainMessage, recipientEncryptionKey);
byte[] messageSerialized = EncryptedMessage.serialize(encryptedMessage);
PendingIntent sent = this.createPendingResult(MainConfig.SMS_SENT, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
SmsManager smsManager = SmsManager.getDefault();
byte[] preparedMessage = new byte[messageSerialized.length + 1];
preparedMessage[0] = 1;
System.arraycopy(messageSerialized, 0, preparedMessage, 1, messageSerialized.length);
if (preparedMessage.length > PDU_SIZE) {
Boolean equalChunks;
Integer mLength = preparedMessage.length;
Integer numOfChunks = mLength / PDU_SIZE;
if (mLength % PDU_SIZE == 0) {
preparedMessage[0] = numOfChunks.byteValue();
equalChunks = true;
} else {
Integer tmpChunks = numOfChunks + 1;
preparedMessage[0] = tmpChunks.byteValue();
equalChunks = false;
}
for (int i = 0; i < numOfChunks; i++) {
byte[] chunkArray = Arrays.copyOfRange(messageSerialized, i * PDU_SIZE, (i + 1) * PDU_SIZE);
smsManager.sendDataMessage(phoneNo, null, MainConfig.SMS_PORT, chunkArray, sent, null); //todo: dodać jeszcze PendingDeliveryIntent
}
if (!equalChunks) {
byte[] chunkArray = Arrays.copyOfRange(messageSerialized, numOfChunks * PDU_SIZE, mLength);
smsManager.sendDataMessage(phoneNo, null, MainConfig.SMS_PORT, chunkArray, sent, null); //todo: dodać jeszcze PendingDeliveryIntent
}
} else {
smsManager.sendDataMessage(phoneNo, null, MainConfig.SMS_PORT, preparedMessage, sent, null); //todo: dodać jeszcze PendingDeliveryIntent
}
}
This is working copy of my method but it works. In receiver you have to read first byte of message to get information how many parts of message it should expect.