Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Sending SMS from Java

Posted on 2011-03-18
6
495 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wondershare 17 79
hibernate example using maven 12 56
going to wrong jsp page 2 33
What browser will run Java? 7 48
Is your Samsung Droid battery constantly dying? SIM card not connecting to your network? Is the display scrambling? This guide will walk you through a list of common Droid headaches and how to quickly solve them.  Poor Battery Life Your phone ba…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

808 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