📄 readmessages.java
字号:
// ReadMessages.java - Sample application.
//
// This application shows you the basic procedure needed for reading
// SMS messages from your GSM device, in synchronous mode.
//
import org.smslib.*;
import java.util.*;
class ReadMessages
{
public static void main(String[] args)
{
LinkedList msgList = new LinkedList();
// Define the CService object. The parameters show the Comm Port used, the Baudrate,
// the Manufacturer and Model strings. Manufacturer and Model strings define which of
// the available AT Handlers will be used.
CService srv = new CService("COM1", 57600, "Nokia", "");
System.out.println();
System.out.println("ReadMessages: Synchronous Reading.");
System.out.println(" Using " + srv._name + " v" + srv._version);
System.out.println();
try
{
// If the GSM device is PIN protected, enter the PIN here.
// PIN information will be used only when the GSM device reports that it needs
// a PIN in order to continue.
srv.setSimPin("0000");
// OK, let connect and see what happens... Exceptions may be thrown here!
srv.connect();
// Lets get info about the GSM device...
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() + "%");
// Depending on your specific model, you may have to uncomment one of the following
// lines in order to be able to read your messages. Different phones store incoming
// messages to either SIM or memory. Default is SIM for most phones.
//
//srv.setStorageMEM();
//srv.setStorageSIM();
// Get the messages in a LinkedList.
// The Class defines which messages should be read. Here we request the readout of
// all messages, whether read or unread.
srv.readMessages(msgList, CIncomingMessage.CLASS_ALL);
// Iterate and display.
// The CMessage parent object has a toString() method which displays all of its
// contents. Useful for debugging, but for a real world application you should
// use the necessary getXXX methods.
for (int i = 0; i < msgList.size(); i ++)
{
CIncomingMessage msg = (CIncomingMessage) msgList.get(i);
System.out.println(msg);
}
// Disconnect - Don't forget to disconnect!
srv.disconnect();
}
catch (Exception e)
{
e.printStackTrace();
}
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -