views:

135

answers:

2

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:

  • Using some sort of internal method but none of the ones I've read about seems to exist anymore.
  • Sending a data message but this requires an additional User-Data Header that the receiving end also doesn't support.

Any help is appreciated :-)

A: 

Try using SmsMessage class:

http://developer.android.com/reference/android/telephony/SmsMessage.html

Create SmsMessage object with createFromPdu() method and use it for sending in SmsManager.

I didn't try it. Good luck.

radek-k
I've looked at that solution too. The problem I find is that there doesn't seem to be a way to actually send an instance of the SmsMessage class as an SMS. Maybe I'm just overlooking something...?
m__
A: 

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.

m__