Java

Java SMS API Wrapper

Integrate SMS into your software using Java.
The API is easy to use. Here is how!

Step 1.
Download “MScience.Sms.jar” from https://github.com/MScience/Dragonfly-Java

Step 2.
Within Eclipse add this as a referenced library for your project.

Java example code:

import com.mscience.SendResult;
import com.mscience.SmsClient;

SmsClient client = new SmsClient("YourAccountId","YourPassword");
SendResult result = client.send("+44123456789","","Hello world",0,true);

if (result.HasError()){
    System.out.println("");
    System.out.printf("Code: %s, Error: %s", 
                      result.getCode(), result.getErrorMessage());
}
else{
    System.out.printf("Code: %s, Id: %d, Balance: %d",
                      result.getCode(),
                      result.getMessageId(), 
                      result.getMessageBalance());
    System.out.printf("Pending: %d, Surcharge: %.6f", 
                      result.getPendingMessages(), 
                      result.getSurchargeBalance());
    System.out.println("");
}

int[] messages = new int[1];
messages[0] = result.getMessageId();

StatusResult[] result2 = client.getMessageStatus(messages);

for(int i=0;i<result2.length;i++){
    System.out.println(result2[i].getStatus());
}

InboundMessageResult[] inbound = client.getDeliveryReceipts();
        
for(InboundMessageResult message : inbound){
    System.out.printf("Code: %s, Id: %d, Source: %s, Destination: %s",
                      message.getCode(),
                      message.getId(),
                      message.getSource(),
                      message.getDestination());
    System.out.printf("Received: %s, SourceId: %d, IsReceipt: %s, text: %s", 
                      message.getReceived(),
                      message.getSourceId(),
                      message.getDeliveryReceipt(),
                      message.getText());
    System.out.println("");
}
Download Sample App
Back to top