2

I'm trying to send an SMS from Android to a J2ME application.

The issue I'm having is that J2ME applications listen on a specific port for incoming SMS messages and I can't get my Android app to send a text SMS to a port.

I've tried sendDataMessage which allows to specify a port, but the J2ME app does not receive it. Also, I've tried adding //wma:port_number to the message body (I've read it here), setting the destination number to the form phone_number:port, all without success.

Also, I can't change the J2ME app since I don't have its source code.

Any ideas for how I can send an SMS from an Android app to a J2ME app on a specific port?

1 Answers1

0

It's been a while since I had the same issue, so hopefully someone has a more useful reply than me. (That would be nice). But here's what I learned when I looked at it:

The difference between JavaME and Android (in regards to SMS sending) is that Android lets you catch incoming SMS on the standard port, while JavaME forces you to use any other port.

A message sent with sendTextMessage() from Android, is identified as an instance of TextMessage on the JavaME platform. But since you can't specify a port on Android, it is send on the standard port - which you can't receive with JavaME.

So you ofcourse look at sendDataMessage(), because it lets you specify a port number. The problem is: A message sent with sendDataMessage() from Android, is identified as an instance of BinaryMessage on the JavaME platform. So the JavaME code listening for a TextMessage will never trigger, since it's a BinaryMessage it's receiving.

The only solution I could find, was therefor to add some code for when a BinaryMessage was received. Slightly different ways of decoding the incoming message, but otherwise doing the same thing.

Sadly you can't do this since you write you don't have the JavaME source, but here's how it could look:

String receivedSMS;

public void notifyIncomingMessage(MessageConnection conn) {
    try {
        Message msg = conn.receive();
        if (msg instanceof TextMessage) { // Message sent from J2ME device
            TextMessage tmsg = (TextMessage) msg;
            receivedSMS = tmsg.getPayloadText();
        } else if (msg instanceof BinaryMessage) { // Message sent from Android device
            BinaryMessage bmsg = (BinaryMessage)msg;
            byte[] ta = bmsg.getPayloadData();
            receivedSMS = new String(ta);
        }
    } catch (Exception e) {
    }
}

That's the only solution I could find back then. If anyone has a better one, I'd like to know too. :-)

mr_lou
  • 1,910
  • 2
  • 14
  • 26