📄 skype.java
字号:
/**
* Send an SMS to one or more cell phone numbers.
* @param numbers the cell phone numbers to send to.
* @param content the message to send.
* @return The new SMS object.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public static SMS sendSMS(String[] numbers, String content) throws SkypeException {
Utils.checkNotNull("numbers", numbers);
return sendSMS(Utils.convertToCommaSeparatedString(numbers), content);
}
/**
* Send an SMS to one cell phone number.
* @param number the cell phone numbers to send to.
* @param content the message to send.
* @return The new SMS object.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public static SMS sendSMS(String number, String content) throws SkypeException {
Utils.checkNotNull("number", number);
Utils.checkNotNull("content", content);
SMS message = createSMS(number, SMS.Type.OUTGOING);
message.setContent(content);
message.send();
return message;
}
/**
* Create a new SMS object to send later using SMS.send .
* @param number Cell phone number to send it to.
* @param type The type of SMS message.
* @return The new SMS object.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
private static SMS createSMS(String number, SMS.Type type) throws SkypeException {
try {
String responseHeader = "SMS ";
String response = Connector.getInstance().executeWithId("CREATE SMS " + type + " " + number, responseHeader);
Utils.checkError(response);
String id = response.substring(responseHeader.length(), response.indexOf(" STATUS "));
return SMS.getInstance(id);
} catch (ConnectorException e) {
Utils.convertToSkypeException(e);
return null;
}
}
/**
* Find all SMS messages.
* @return Array of SMS messages.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public SMS[] getAllSMSs() throws SkypeException {
return getAllSMSs("SMSS");
}
/**
* Find all missed SMS messages.
* @return Array of SMS messages.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public SMS[] getAllMissedSMSs() throws SkypeException {
return getAllSMSs("MISSEDSMSS");
}
/**
* Find all SMS message of a certain type.
* @param type The type to search for.
* @return Array of found SMS messages.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
private SMS[] getAllSMSs(String type) throws SkypeException {
try {
String command = "SEARCH " + type;
String responseHeader = "SMSS ";
String response = Connector.getInstance().execute(command, responseHeader);
String data = response.substring(responseHeader.length());
String[] ids = Utils.convertToArray(data);
SMS[] smss = new SMS[ids.length];
for (int i = 0; i < ids.length; ++i) {
smss[i] = SMS.getInstance(ids[i]);
}
return smss;
} catch (ConnectorException e) {
Utils.convertToSkypeException(e);
return null;
}
}
/**
* Leave a voicemail in a other Skype users voicemailbox.
* @param skypeId The Skype user to leave a voicemail.
* @return The new Voicemail object.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public static VoiceMail voiceMail(String skypeId) throws SkypeException {
try {
String responseHeader = "VOICEMAIL ";
String response = Connector.getInstance().executeWithId("VOICEMAIL " + skypeId, responseHeader);
Utils.checkError(response);
String id = response.substring(responseHeader.length(), response.indexOf(' ', responseHeader.length()));
return VoiceMail.getInstance(id);
} catch (ConnectorException e) {
Utils.convertToSkypeException(e);
return null;
}
}
/**
* Gets the all voice mails.
* @return The all voice mails
* @throws SkypeException If there is a problem with the connection or state at the Skype client.
*/
public static VoiceMail[] getAllVoiceMails() throws SkypeException {
try {
String command = "SEARCH VOICEMAILS";
String responseHeader = "VOICEMAILS ";
String response = Connector.getInstance().execute(command, responseHeader);
String data = response.substring(responseHeader.length());
String[] ids = Utils.convertToArray(data);
VoiceMail[] voiceMails = new VoiceMail[ids.length];
for (int i = 0; i < ids.length; ++i) {
voiceMails[i] = VoiceMail.getInstance(ids[i]);
}
return voiceMails;
} catch (ConnectorException ex) {
Utils.convertToSkypeException(ex);
return null;
}
}
/**
* Add an AP2AP capable application.
* @param name The name of the AP2AP application.
* @return Application object reference.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public static Application addApplication(String name) throws SkypeException {
return Application.getInstance(name);
}
/**
* Gets the current audio input device of this Skype.
*
* @return the audio input device name of this Skype, or <code>null</code>
* if the device is the default.
* @throws SkypeException when connection has gone bad or ERROR reply.
* @see #setAudioInputDevice(String)
*/
public static String getAudioInputDevice() throws SkypeException {
return convertDefaultDeviceToNull(Utils.getProperty("AUDIO_IN"));
}
/**
* Gets the current audio output device of this Skype.
*
* @return the audio output device name of this Skype, or <code>null</code>
* if the device is the default.
* @throws SkypeException when connection has gone bad or ERROR reply.
* @see #setAudioOutputDevice(String)
*/
public static String getAudioOutputDevice() throws SkypeException {
return convertDefaultDeviceToNull(Utils.getProperty("AUDIO_OUT"));
}
/**
* Get the current video input device used by the Skype Client.
* @return String with the device name or null if there isn't one.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public static String getVideoDevice() throws SkypeException {
return convertDefaultDeviceToNull(Utils.getProperty("VIDEO_IN"));
}
/**
* Return null if the default device is used.
* @param deviceName Name of the device to check.
* @return <code>null</code> if device is default else devicename.
*/
private static String convertDefaultDeviceToNull(String deviceName) {
if (isDefaultDevice(deviceName)) {
return null;
} else {
return deviceName;
}
}
/**
* Compare the devicename to the default value.
* @param deviceName the string to compare.
* @return true if devicename is equal to defaultname.
*/
private static boolean isDefaultDevice(String deviceName) {
return "".equals(deviceName);
}
/**
* Sets the current audio input device of this Skype.
*
* @param deviceName
* the audio input device name. A <code>null</code> value means
* the default.
* @throws SkypeException when connection has gone bad or ERROR reply.
* @see #getAudioInputDevice()
*/
public static void setAudioInputDevice(String deviceName) throws SkypeException {
Utils.setProperty("AUDIO_IN", convertNullToDefaultDevice(deviceName));
}
/**
* Sets the current audio output device of this Skype.
*
* @param deviceName
* the audio output device name. A <code>null</code> value
* means the default.
* @throws SkypeException when connection has gone bad or ERROR reply.
* @see #getAudioOutputDevice()
*/
public static void setAudioOutputDevice(String deviceName) throws SkypeException {
Utils.setProperty("AUDIO_OUT", convertNullToDefaultDevice(deviceName));
}
/**
* Set the video device used by the Skype client.
* @param deviceName name of the device to set.
* @throws SkypeException when connection has gone bad or ERROR reply.
*/
public static void setVideoDevice(String deviceName) throws SkypeException {
Utils.setProperty("VIDEO_IN", convertNullToDefaultDevice(deviceName));
}
/**
* Convert a <code>null</code> to the default device.
* @param deviceName String to convert.
* @return Default device string.
*/
private static String convertNullToDefaultDevice(String deviceName) {
if (deviceName == null) {
return "";
} else {
return deviceName;
}
}
/**
* Get the singleton instance of the users profile.
* @return Profile.
*/
public static synchronized Profile getProfile() {
if (profile == null) {
profile = new Profile();
}
return profile;
}
/**
* Gets the all chats.
*
* @return The all chats
*
* @throws SkypeException If there is a problem with the connection or state at the Skype client.
*/
public static Chat[] getAllChats() throws SkypeException {
return getAllChats("CHATS");
}
/**
* Gets the all chats which are open in the windows.
*
* @return The all chats which are open in the windows
*
* @throws SkypeException If there is a problem with the connection or state at the Skype client.
*/
public static Chat[] getAllActiveChats() throws SkypeException {
return getAllChats("ACTIVECHATS");
}
/**
* Gets the all chats which include unread messages
*
* @return The all chats which include unread messages
*
* @throws SkypeException If there is a problem with the connection or state at the Skype client.
*/
public static Chat[] getAllMissedChats() throws SkypeException {
return getAllChats("MISSEDCHATS");
}
/**
* Gets the all recent chats in the locally-cached history.
*
* @return The all recent chats in the locally-cached history
*
* @throws SkypeException If there is a problem with the connection or state at the Skype client.
*/
public static Chat[] getAllRecentChats() throws SkypeException {
return getAllChats("RECENTCHATS");
}
/**
* Gets the all bookmarked chats.
*
* @return The all bookmarked chats
*
* @throws SkypeException If there is a problem with the connection or state at the Skype client.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -