Is there a way to send sms from android mobile to server?

I have an Android app in my mobile device where I fill in some data and then I want to add that data to the database. So I am planning to add a button (sms button) to my application, by clicking this button, the data should be updated to the server database or just dump the data on the server. So I want to know if we can send sms to the server? And if so, how?
Note. I have a server with a static IP address.

+3


source to share


3 answers


try sending data to server.

public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "msgId"));
        nameValuePairs.add(new BasicNameValuePair("stringdata", "Msg u want send"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request

        HttpResponse response = httpclient.execute(httppost);
        Log.v("myapp", "response " + response.getEntity());
        String responseBody = EntityUtils.toString(response.getEntity());


    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
} 

      



You can refer to Android HttpPost: how to get the result http://www.anddev.org/doing_http_post_with_android-t492.html

+2


source


You can try with an HTTP request and have a serveride script (php / java / ...) collect the data and put it in the database. Encoding can be done with JSON (or one of its variants). The fact that you have a static IP address makes this pretty easy.



If you have dataconnection (and since you are using a smartphone, you probably do), you are better off using your internet connection.

+1


source


When you add a GPRS modem to your server and insert an active SIM card into it, you can send SMS messages to that number, and then you still need a service that will read your SMS messages and convert / dump data to the server itself.

0


source







All Articles