o7planning

Skype Java API Tutorial with Examples

  1. Library
  2. Principle of operation
  3. Create Project
  4. Example, sending a message to another skype account
  5. Calling
  6. Modify profile Information
  7. Automatic answer
  8. Create MenuItem on skype

1. Library

You can download jar file for using or declaring the use through Maven.
After opening jar file with winrar, you will see it contains dll files for both window 32bit and 64bit.
  • skype-java-api-1.4.jar

2. Principle of operation

On the computer running Java program interactive with Skype, you have to install Skype and ensure that it is operating (It means you log in with a nickname).
Note: this Skype Java API library has been verified running well on Window operating system, but I have not tested it on other operating system yet!

3. Create Project

Creating a new Project, creating libs directory, copy the file skype-java-api-*.jar into libs folder as illustrated below.
To Declare library right-clicking on Project and select Properties:

4. Example, sending a message to another skype account

Important Note:
Skype version> = 7 stop support to send messages from a 3rd software (for example Java Skype API). Therefore on the computer sending automated messages you need to install Skype 6.x
You can download Skype 6.3.x here:
Constants.java
package org.o7planning.tutorial.skype;

public class Constants {
   
    // Skype Nick name of the recipient.
    // Enter the nick name before the start of the examples.
    public static final String SKYPE_FRIEND_NICKNAME = "friend_nick_name";

}
SendChatMessage.java
package org.o7planning.tutorial.skype;

import com.skype.Skype;
import com.skype.SkypeException;

public class SendChatMessage {

   public static void main(String[] args) {

       try {
           String message = "Hello, This is test message";

           Skype.chat(Constants.SKYPE_FRIEND_NICKNAME).send(message);

           System.out.println("Message sent!");

       } catch (SkypeException e) {
           e.printStackTrace();
       }

   }
}
In the first run SendChatMessage class, you will receive an Exception while on Skype has message ask permission to allow Java to use Skype. Click "Allow" to allow.

5. Calling

Another example allows you to make a call to an other nick name from Java.
MakeCall.java
package org.o7planning.tutorial.skype;

import com.skype.Skype;
import com.skype.SkypeException;

public class MakeCall {

  public static void main(String[] args) {
      try {
          Skype.call(Constants.SKYPE_FRIEND_NICKNAME);
      } catch (SkypeException e) {
          e.printStackTrace();
      }
  }

}
After MakeCall class runs, Skype on your computer where your Java program is running will send a call to Skype of the other person.

6. Modify profile Information

You can change your skype information such as profile, date of birth, photo, ... from your Java class.
EditProfile.java
package org.o7planning.tutorial.skype;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import com.skype.Profile;
import com.skype.Skype;

public class EditProfile {

   public static void main(String[] args) {

       String moodText = "No thing to do today!";

       try {
           Profile profile =Skype.getProfile();

           //
           profile.setMoodMessage(moodText);
           
           // Full Name
           profile.setFullName("My Name");

           // Change Avatar
           File avataFile = new File("C:/mypictures/avatar.png");
           BufferedImage image = ImageIO.read(avataFile);
           profile.setAvatar(image);

       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}

7. Automatic answer

The following example illustrates an automatic reply to messages sent to your Skype.
AutoAnswering.java
package org.o7planning.tutorial.skype;

import com.skype.ChatMessage;
import com.skype.ChatMessageAdapter;
import com.skype.Skype;
import com.skype.SkypeException;
import com.skype.User;

public class AutoAnswering {

    public static void main(String[] args) throws Exception {

        System.out.println("Start Auto Answering ...");
        
        // To prevent exiting from this program
        Skype.setDaemon(false);
        
        
        Skype.addChatMessageListener(new ChatMessageAdapter() {
            public void chatMessageReceived(ChatMessage received)
                    throws SkypeException {
                if (received.getType().equals(ChatMessage.Type.SAID)) {

                    // Sender
                    User sender =received.getSender();    
                    
                    System.out.println(sender.getId() +" say:");
                    System.out.println(" "+received.getContent() );
                    
                    received.getSender().send(
                            "I'm working. Please, wait a moment.");
                    
                    System.out.println(" - Auto answered!");
                }
            }
        });
        
        
        System.out.println("Auto Answering started!");
    }

}
Run class AutoAnswering:
Now the program is listening to messages sent from other Skype nicknames and will automatically reply to those messages. The automatic reply stops when you stop Java program (Press the red button as the above image)
Receiving messages sent to

8. Create MenuItem on skype

We will create a Menultem on Skype to do some task when you click on it.
ShowMenuItem.java
package org.o7planning.tutorial.skype;

import com.skype.MenuItem;
import com.skype.MenuItemClickEvent;
import com.skype.MenuItemListener;
import com.skype.Skype;
import com.skype.SkypeClient;
import com.skype.SkypeException;
 

public class ShowMenuItem {
    
    
    public static void main(String[] args) throws Exception {

        // Write log
        Skype.setDebug(true);
        
        //
        Skype.setDaemon(false);


        // Add a MenuItem in Skype (see illustration below)
        final MenuItem item = SkypeClient.addMenuItem(MenuItem.Context.TOOLS,
                "Test menu", null, null, true, null, true);
        
        item.setHint("This is test menu item");
        
        // Handle Event
        item.addMenuItemListener(new MenuItemListener() {
            public void menuItemClicked(MenuItemClickEvent event)
                    throws SkypeException {
                System.out.println("Test menu is clicked.");
                
                // Dispose Menu
                // event.getMenuItem().dispose();
            }
        });
    }
}
Results of running the example:
View on skype: