Solved

Sending SMS from Java

Posted on 2011-03-18
6
487 Views
Last Modified: 2012-05-11
How to send SMS using Java API? (If someone can help with free SMS in India, it would be great)
On a wider note, how to interface with Mobile network using desktop Java? Is it possible?
Could we call/divert mobile call using Java on desktop?
Thanks!
0
Comment
Question by:preraksheth
6 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 35164437
0
 
LVL 2

Author Comment

by:preraksheth
ID: 35164519
Thanks, but I should have added to my original question - "Thru internet".
In other words, I would like to send SMS thru internet to a desired number(or a set of numbers)
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35167908
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 40

Expert Comment

by:gurvinder372
ID: 35179505
@samirbhogayta: please check my previous reply. The link that you have posted is the first link that i posted in my previous reply.
0
 
LVL 2

Author Closing Comment

by:preraksheth
ID: 35179814
The solution is useful, but does not answer my original question completely about a free sms service in India. Anyhow, this is probabaly the closest that we can get
0
 
LVL 1

Expert Comment

by:tsheraman22
ID: 35183458
Here is some information on sending from Java. The messages are not free, but you do get a free trial account.

http://www.redoxygen.com/developers/java/

Java API

Use this API to send text messages from Java.

 Simple HTTP request
 Encrypted communication over SSL
 Long SMS (up to 765 characters)
 Delivery status via function return code
 Email replies

Example

public static int  SendSMS(String strAccountId,String strEmail,String strPassword,
String strMSISDN,String strMessage,StringBuffer strResponse)
{
      String  sRequestURL;
      String  sData;
      int nResult = -1;

      sRequestURL = "http://www.redoxygen.net/sms.dll?Action=SendSMS";

      try
      {
            sData  = ("AccountId="  + URLEncoder.encode(strAccountId,"UTF-8"));
            sData += ("&Email="     + URLEncoder.encode(strEmail,"UTF-8"));
            sData += ("&Password="  + URLEncoder.encode(strPassword,"UTF-8"));
            sData += ("&Recipient=" + URLEncoder.encode(strMSISDN,"UTF-8"));
            sData += ("&Message="   + URLEncoder.encode(strMessage,"UTF-8"));

            URL urlObject = new URL(sRequestURL);
            
            HttpURLConnection con = (HttpURLConnection) urlObject.openConnection();
            con.setRequestMethod("POST");
            con.setDoInput (true);
            con.setDoOutput (true);

            DataOutputStream out;
            out = new DataOutputStream(con.getOutputStream());
            out.writeBytes (sData);
            out.flush();
            out.close();
            
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                        
            String inputLine;
            StringBuffer responseBuffer = new StringBuffer();

            while ((inputLine = in.readLine()) != null)
            {
                  responseBuffer = responseBuffer.append(inputLine);
                  responseBuffer = responseBuffer.append("\n\n\n");
            }
      
            strResponse.replace(0,0,responseBuffer.toString());

            String sResultCode = strResponse.substring(0,4);
            nResult = Integer.parseInt(sResultCode);
            
            in.close();
      }
      
      catch (Exception e)
      {
            System.out.println("Exception caught sending SMS\n");
            nResult = -2;
      }
      return nResult;
}
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Want to know why your HTC Droid DNA keeps turning on and off, or why it doesn’t seem to charge at all? This guide walks you through a laundry list of items to check to make sure you get the most out of your HTC Droid DNA.  Phone Will Not Turn On …
I'm Dumb-phoned(ed) Last week, I noticed this message when adding events to my Google Calendar: On June 27th (2015), Google is removing SMS as a notification option for Google Calendar events.  Their assumption is that enough people have smart p…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now