Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

19.3 Sending Binary Messages

The payload of an SMS message can carry binary data. You will need a BinaryMessage instead of a TextMessage, but the basic procedure is the same.

public void sendBinary(String address, byte[] data)
    throws IOException, InterruptedException {
  String cs = "sms://" + address + ":50001";
  MessageConnection mc = (MessageConnection)
      Connector.open(cs);
  BinaryMessage bm = (BinaryMessage)
      mc.newMessage(MessageConnection.BINARY_MESSAGE);
  bm.setPayloadData(data);
  mc.send(bm);
}

Remember, you've only got 152 bytes in a message, although longer payloads will be split into multiple messages.

  • + Share This
  • 🔖 Save To Your Account