Click here to Skip to main content
15,867,845 members
Articles / Programming Languages / Java
Tip/Trick

How to send SMS using Java with a HSDPA Dongle.

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
12 Nov 2012CPOL3 min read 98.1K   3   19
Simply send SMS using Java with GSM Modem or HSDPA Dongle

Hello Everyone!

Today I am going to tell you about how to simply send SMS by using your HSDPA dongle or GSM modem. Cool! Isn't it? yes It's not that difficult either. I have tried so many ways to accomplish this. After so many attempts I got the way to do it right. So I will tell you how I have done that.



Basically this was created by using SMSLib which is an open source library for Java. After studying the API I have created a simple API wrapper for convenience. I have hosted the open source code in Github with a sample project named SMS.Dura.Wrapper. For this sample project I have made and used a prebuilt Jar library named smsdura-1.0.jar which works as the wrapper. So in your project you have to simply import that smsdura-1.0.jar, just configure the modem, put the message, TP, and send. Now SMS from Java? It' s very easy! I will tell you how to do that. May be it will add more value for your project as well.

I will guide you through the rest of the process. Okay let's start!

1. First of all you have to Download this sample project.

2. Now we have to copy few files in the <Extras folder> to your Java Classpath. [Normally JDKDIR can be found in > C:\Program Files\Java] Go to that path and do it as said. Detailed instructions are listed below.

---------------------------    
    External Configurations for the JVM on the targeted machine. (Strictly Recommended!)
    [These files can be found in <extras> folder of the Project path.)
---------------------------
Java Comm Installation <comm dir>
-----------------------------------
    File comm.jar should go under JDKDIR/jre/lib/ext/ 
    File javax.comm.properties should go under JDKDIR/jre/lib/
    Library files (i.e. win32com.dll for Win32 or the .so Linux library files) should go under JDKDIR/jre/bin/
    If you have a separate JRE directory, do the same copies for the JREDIR directory!
RxTx Installation <rxtx dir>
-----------------------------------
    File RXTXcomm.jar should go under JDKDIR/jre/lib/ext/
    The necessary library (e.g.. for Linux 32bit, the librxtxSerial.so) should go under JDKDIR/jre/bin/
    If you have a separate JRE directory, do the same copies for the JREDIR directory!

Huh! All the hard work has been done. be cool now Smile | :)

3. Okay now simply open the project from Netbeans IDE or whatever IDE you are using.

4. Importing the Required Dependencies. I have imported all the Jars for this project. So by default you have to do nothing with importing. But in your project you have to import few Jar files you can found in <lib> folder. You have to import all the Jars in that folder.

5. Okay done! Now take a look at this code.

Java
package logic;

import com.harshadura.gsm.smsdura.GsmModem;

public class TestSMS {

    private static String port = "COM3"; //Modem Port.
    private static int bitRate = 115200; //this is also optional. leave as it is.
    private static String modemName = "ZTE"; //this is optional.
    private static String modemPin = "0000"; //Pin code if any have assigned to the modem.
    private static String SMSC = "+9477000003"; //Message Center Number ex. Mobitel

    public static void main(String[] args) throws Exception {
        GsmModem gsmModem = new GsmModem();
        GsmModem.configModem(port, bitRate, modemName, modemPin, SMSC);
        gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg) 
    } 
}

Okay in here, you will notice that you have to first find out the port number of your USB modem/dongle. For that you can simply right click the MyComputer Icon > go to Mange > then Search for Modems > then it will pop up a interface with several tabs. Okay then you can simply notice theirs a Name called port. In front of that there is the port number. Now you know the port number. Insert that into the code.

Modem name is a optional thing. Give it some relevant name.

Bit rate? Leave it as it is. Or change to a proper one. The number will change depending modem to modem. so just leave as it as.

Some modems are using PIN numbers for Security. Does your one also using such a pin? If so please insert it to the code.

Well then You have to insert the SMS Message Center Number. You already know that. Suppose you own a Mobitel/Dialog SIM you can easily find out it in your Mobile phone/Dongle Message Settings. So get the Number and paste it with +94 prefix.

Wow! Now all are ready. we have completed the Configuration of the modem. Cool isnt it? Big Grin | :-D

Okay now please disconnect your Modem from the Internet Before continue. If its connected to the internet or may be the Mobile Partner or whatever the software you are using to connect with the modem, can disturb our work. So just close them All. You better restart your computer to refresh the Modem Port. Don't Connect it to the Internet!!

Well now we are ready to send SMS thorough Java.. Be cool..! 

C#
gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg)

Just put some telephone number and message for the body. Then do a Clean and Build. Now simply Run the project.

Okay everything has to be working properly.. Wait, give it some time! Did you get the message? Big Grin | :-D

So that's how we can simply send SMS using Java with our USB modem. Cool way.. huh!

Cheers!
 - Harsha

Please note that this is an API wrapper for SMSLib and the Main API has more functionality than this wrapper code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Sri Lanka Sri Lanka
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
QuestionSOLUCION: PROBLEMA DE PUERTO PARA SMS API JAVA ECLIPSE MODEM Pin
Member 1340067330-Mar-19 19:45
Member 1340067330-Mar-19 19:45 
QuestionCan't run on 64 bit machine Pin
Sharipov_Shohruh21-Dec-16 22:13
professionalSharipov_Shohruh21-Dec-16 22:13 
QuestionWorks well for first SMS Pin
harly197830-Jun-16 15:16
harly197830-Jun-16 15:16 
PraiseGood work ! Pin
Denuwan Himanga Hettiarachchi3-Jan-16 2:58
Denuwan Himanga Hettiarachchi3-Jan-16 2:58 
QuestionSend SMS Java with header (from "text" instead of "number") Pin
Member 1176396713-Jun-15 14:17
Member 1176396713-Jun-15 14:17 
QuestionIs this one have GUI or do we have to create it? Pin
Vimukthi Warnakulasooriya1-Nov-14 20:03
Vimukthi Warnakulasooriya1-Nov-14 20:03 
Questionhello Pin
Member 1101256514-Aug-14 0:07
Member 1101256514-Aug-14 0:07 
Questionsleep Time Pin
Neyon Denz18-Jul-14 19:45
Neyon Denz18-Jul-14 19:45 
QuestionSMS System using AT command Pin
Member 1051887111-Jan-14 23:36
Member 1051887111-Jan-14 23:36 
Questionpin number Pin
Chamith Saranga15-Nov-13 14:06
Chamith Saranga15-Nov-13 14:06 
Questionසුපිරි................... ආ..................................... Pin
Member 1034330817-Oct-13 16:54
Member 1034330817-Oct-13 16:54 
AnswerPlease check my blog-post's comments section for already answered stuff towards most of your questions (FAQs): >> Check Link Pin
harshadura1-Jun-13 1:54
harshadura1-Jun-13 1:54 
GeneralMy vote of 5 Pin
chaitu from cheenai29-May-13 0:51
chaitu from cheenai29-May-13 0:51 
Questionunable to run the application in 64bit machine Pin
rahulr273-Apr-13 23:26
rahulr273-Apr-13 23:26 
AnswerRe: unable to run the application in 64bit machine Pin
Sharipov_Shohruh22-Dec-16 1:36
professionalSharipov_Shohruh22-Dec-16 1:36 
GeneralMy vote of 4 Pin
rahulr2719-Mar-13 8:22
rahulr2719-Mar-13 8:22 
QuestionGetting exception Pin
Member 398674427-Nov-12 9:39
Member 398674427-Nov-12 9:39 
GeneralI am getting Exception . Pin
Member 398674427-Nov-12 9:32
Member 398674427-Nov-12 9:32 
GeneralRe: I am getting Exception . Pin
Sharipov_Shohruh22-Dec-16 1:37
professionalSharipov_Shohruh22-Dec-16 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.