0

おはようございます、次のコードがあります。

int numero = 22492;
String  PhnNoStr = String.valueOf (numero);
String transaction = WriteText(tipoTransacao);
String SmsStr = "ECART" + "" + transaction + idToken;
System.out.println ("Message:" + smsStr);
MessageConnection msgCon = null;
msgCon = (MessageConnection) Connector.open ("sms :/ /" + + phnNoStr ": 500");
TextMessage TxtMsg = (TextMessage) msgCon.newMessage (MessageConnection.TEXT_MESSAGE);
txtMsg.setPayloadText (smsStr);
msgCon.send (TxtMsg);

そのメッセージを送信すると、デフォルトでメッセージが返されます。このメッセージを送受信できますが、このメッセージを受信したときに傍受する必要があります。これを行う方法を知っている人はいますか?

ありがとうございました

4

1 に答える 1

0

You can use PushRegistry to have your midlet launched when a SMS is received and midlet is not running.

PushRegistry.registerConnection("sms://:500", "your_package.Your_MIDlet", "*");

To handle incoming SMS, you need to open connection and listen for incoming message, eg:

class SMSHandler implements MessageListener, Runnable {
    public void start() {
        ...
        connection = (MessageConnection) Connector.open("sms://:500", Connector.READ);
        connection.setMessageListener(this);
    }

    public void notifyIncomingMessage(MessageConnection messageConnection) {
        (new Thread(this)).start();
    }

    public void run() {
        final Message message = connection.receive();
        ...
    }

(The reason for processing the message in another thread is that blocking I/O should not be done in system callback - at least WTK emulator will print warning, and on some phones midlet will just freeze).

于 2013-09-05T16:28:05.187 に答える