Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How To send sms from javaapplication to mobile

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool How To send sms from javaapplication to mobile

    import java.net.*;
    import java.io.*;

    public class sendsms {


    public static String server;
    public static String user;
    public static String password;
    public static String phonenumber;
    public static String text;
    public static String data;
    public static String udh;
    public static String pid;
    public static String dcs;
    public static String sender;
    public static String validity;
    public static String servicetype;
    public static String smscroute;
    public static String receiptrequested;
    public static String sourceport;
    public static String destport;
    public static String delayuntil;
    public static String voicemail;
    public static String wapurl;
    public static String wapsl;

    public static String url_str;

    public static void init () {
    server = null;
    user = null;
    password = null;
    phonenumber = null;
    text = null;
    data = null;
    udh = null;
    pid = null;
    dcs = null;
    sender = null;
    validity = null;
    servicetype = null;
    smscroute = null;
    receiptrequested = null;
    sourceport = null;
    destport = null;
    delayuntil = null;
    voicemail = null;
    wapurl = null;
    wapsl = null;
    }

    public static void setvar (String argname, String argvalue) {

    if (argname != null) {
    if (argvalue != null) {
    url_str = url_str + "&" + argname + "=";
    try {
    String encoded = URLEncoder.encode (argvalue, "UTF-8");
    url_str = url_str + encoded;
    }
    catch (UnsupportedEncodingException e) {
    url_str = url_str + argvalue;
    }
    }
    }

    }

    public static String send () {


    String returnstring;

    returnstring = null;

    if (server == null) {
    System.out.println("sendsms.server value not set");
    return returnstring;
    }

    url_str = server + "?";
    setvar("user", user);
    setvar("password", password);
    setvar("phonenumber", phonenumber);
    setvar("text", text);
    setvar("data", data);
    setvar("udh", udh);
    setvar("pid", pid);
    setvar("dcs", dcs);
    setvar("sender", sender);
    setvar("validity", validity);
    setvar("servicetype", servicetype);
    setvar("smscroute", smscroute);
    setvar("receiptrequested", receiptrequested);
    setvar("sourceport", sourceport);
    setvar("destport", destport);
    setvar("delayuntil", delayuntil);
    setvar("voicemail", voicemail);
    setvar("wapurl", wapurl);
    setvar("wapsl", wapsl);

    try {
    URL url2=new URL(url_str);

    HttpURLConnection connection = (HttpURLConnection) url2.openConnection();
    connection.setDoOutput(false);
    connection.setDoInput(true);

    String res=connection.getResponseMessage();

    System.out.println("Response Code ->"+res);

    int code = connection.getResponseCode () ;

    if ( code == HttpURLConnection.HTTP_OK ) {
    //Get response data.
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

    String str;

    while( null != ((str = in.readLine()))) {
    if (str.startsWith("MessageID=")) {
    returnstring = returnstring + str + "\r\n";
    System.out.println(str);
    }
    }
    connection.disconnect() ;
    }
    }
    catch(IOException e) {
    System.out.println("unable to create new url"+e.getMessage());
    }
    return returnstring;
    }
    public static void main(String[] args) {
    sendsms.init();
    sendsms.server = "http://way2sms.com/";
    sendsms.user = "test";
    sendsms.password = "test";
    sendsms.phonenumber = "+9999999999";
    sendsms.text = "This is a test message";
    sendsms.send();

    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,106
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: How To send sms from javaapplication to mobile

    Is this a question or a demonstration of working code?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. SMS from Java
    By Susanto in forum Java Theory & Questions
    Replies: 0
    Last Post: October 19th, 2012, 09:15 AM
  2. Replies: 0
    Last Post: July 26th, 2011, 10:31 PM
  3. Replies: 2
    Last Post: March 3rd, 2011, 01:22 PM
  4. SMS Textspeak Corrector
    By SHENGTON in forum Java ME (Mobile Edition)
    Replies: 4
    Last Post: January 17th, 2011, 05:58 AM
  5. [help] cant receive sms
    By ordinarypeople in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: April 4th, 2010, 02:41 PM