[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sending SMS from Java

Posted on 2011-03-18
6
Medium Priority
?
529 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
[X]
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
6 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1500 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…
Suggested Courses

649 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