sendmessage.java

来自「How to use jsmsengine to receive sms」· Java 代码 · 共 117 行

JAVA
117
字号
import org.jsmsengine.*;class SendMessage{    public static void main(String[] args)    {       int status;       // Create jSMSEngine service.       CService srv = new CService("com6", 115200);       System.out.println();       System.out.println("SendMessage(): sample application.");       System.out.println("  Using " + srv._name + " " + srv._version);       System.out.println();       try       {           //  Initialize service.            srv.initialize();           //  Set the cache directory.           srv.setCacheDir(".\\");           //  Set the phonebook.           //  srv.setPhoneBook("../misc/phonebook.xml");           //  Connect to GSM device.           status = srv.connect();           //  Did we connect ok?           if (status == CService.ERR_OK)           {              //  Set the operation mode to PDU - default is ASCII.              srv.setOperationMode(CService.MODE_PDU);              // Set the SMSC number (set to default).              srv.setSmscNumber("");              //  Print out GSM device info...              System.out.println("Mobile Device Information: ");              System.out.println(" Manufacturer  : " + srv.getDeviceInfo().getManufacturer());              System.out.println(" Model         : " + srv.getDeviceInfo().getModel());              System.out.println(" Serial No     : " + srv.getDeviceInfo().getSerialNo());              System.out.println(" IMSI          : " + srv.getDeviceInfo().getImsi());              System.out.println(" S/W Version   : " + srv.getDeviceInfo().getSwVersion());              System.out.println(" Battery Level : " + srv.getDeviceInfo().getBatteryLevel() + "%");              System.out.println(" Signal Level  : " + srv.getDeviceInfo().getSignalLevel() + "%");              //  Create a COutgoingMessage object and dispatch it.              //  *** Please update the phone number with one of your choice ***              COutgoingMessage msg = new COutgoingMessage("+6596777992", "Message from jSMSEngine API.");              //  Character set is 7bit by default - lets make it UNICODE :)              //  We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,              //     this does not make ANY difference...              msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);              if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");              else System.out.println("Message Failed!");              // Disconnect from GSM device.              srv.disconnect();           }           else System.out.println("Connection to mobile failed, error: " + status);       }       catch (Exception e)       {           e.printStackTrace();       }       System.exit(0);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?