1

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 :-)

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
m__
  • 1,721
  • 1
  • 17
  • 30
  • Hi, Can you please add the classes or the link where did you find GsmAlphabet? I want to send SMS via USSD and I have problem with the encoding of the string I am sending in the ussd code. I can share my code for sending ussd message if you want. Thank you. –  May 14 '11 at 18:31
  • The GsmAlphabet is taken from the [android open source project](http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=telephony/java/com/android/internal/telephony/GsmAlphabet.java;h=57d73e3758f5de2d52abc8deca66fd797f3a19e2;hb=HEAD) – m__ May 16 '11 at 05:36

2 Answers2

2

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__
  • 1,721
  • 1
  • 17
  • 30
1

Try using SmsMessage class:

https://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.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
plugmind
  • 7,926
  • 4
  • 34
  • 39
  • 1
    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__ Aug 24 '10 at 10:46