简体   繁体   中英

Send SMS from Java form using JSSC and Android phone

I need your help in this topic:

I want to send text messages from a phone that is connected with USB to a laptop and sending the text should be write from a Java form. I tried to do some code using JSSC library, but something it doesn't work because the SMS is not sent. Connection is good, communication is good too, but the text message is not sent. Can either of you help me with this?

public static void main(String[] args) {
    SerialPort port = new SerialPort("COM3");
    char enter = 13;
    char control_z=26;
    char comilla = 34;
    try {
        System.out.println("Port open: " + port.openPort());
        System.out.println("Params setted: " + port.setParams(9600, 8, 1, 0));     

        System.out.println("Set to SMS: " + port.writeBytes(("AT+CMGF=1"+enter).getBytes()));
        System.out.println("Set the destinatar: " + port.writeBytes(("AT+CMGS"+comilla+"+phone_number"+comilla+enter).getBytes()));
        System.out.println("Set the text: " + port.writeBytes(("text"+control_z).getBytes()));

        System.out.println("Port closed: " + port.closePort());
    }
    catch (SerialPortException ex){
        System.out.println(ex);
    }
}

You are aborting the commands you are issuing. You should be reading and parsing the responses you get back from the modem. See the first part of this answer , and also this and this answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM