androidencodingsmspdu7-bit

Defining data encoding of SMS messages in Android


I'm working on an application using the SMS apis for android. The receiving end is an embedded unit that only supports 7-bit encoded SMS and the string I'm sending consists only of symbols from this particular alphabet which makes you think that Android is going to send it encoded as 7 bit. But that is not the case.

Therefore I'm searching for a way to specify what encoding to use. See below for what my code looks like today. The method gsm7BitPackedToString turns a byte-array to a 7-bit string, i.e. the string only consists of 7-bit compatible characters and is copied from the internal android api.

private static boolean sendMessage(String tel,byte[] message,int septets) {
    SmsManager sms = SmsManager.getDefault();
    if (septets != -1) {
        String a = GsmAlphabet.gsm7BitPackedToString(message,0,septets);
        sms.sendTextMessage(tel, null, a, null, null);
        return true;
    }
    return false;
}

I have considered the following solutions:

Any help is appreciated :-)


Solution

  • Well, the solution wasn't as hard as it may seem. The GsmAlphabet class that I borrowed from the android project had some encoding bugs. I replaced it with the latest from the git repository and now it all seems to work like it is supposed to.

    Lesson learned: Always double and triple check things that should work.