Accept UniCode SMS

1.1k views Asked by At

I want to receive UniCode SMS from jSMPP.

If Data Coding is 8, I want to convert it to Unicode symbols.

For this I use HexUtil.convertBytesToHexString function.

But it doesn't convert it correctly. How can I convert this string?

        @Override
    public void onAcceptDeliverSm(DeliverSm arg0)
            throws ProcessRequestException {
        if (MessageType.SMSC_DEL_RECEIPT.containedIn(arg0.getEsmClass())) {
            // Deliver SM
        } else {
            byte[] data = arg0.getShortMessage();
            String text = null;

            if (arg0.getShortMessage() != null) {
                if (arg0.getDataCoding() == (byte) 8) {
                    text = HexUtil.convertBytesToHexString(data, 0,
                            data.length);
                } else {
                    text = new String(data);
                }
            }

                    System.out.println("Text -> " + text);
        }
    }
1

There are 1 answers

0
Dmitry Sh On

Try this way (use you own encoding detection):

        if (msg.getEncoding().equals(Message.MessageEncodings.ENC7BIT)) {
            text = msg.getText();
        } else if (msg.getEncoding().equals(Message.MessageEncodings.ENCUCS2)) {
            try {
                text = new String(msg.getText().getBytes(), "UTF-16");
            } catch (Exception ex) {
                Logger.getLogger("smpp").error("Can't parce USC2 text: " + msg.getText() + ", " + ex.getMessage());
            }
        }

also u can try UTF-16LE, UTF-16BE encoding, if UTF-16 dont display correct