【问题标题】:Is there a way to send sms from Android mobile phone to a server?有没有办法从安卓手机发送短信到服务器?
【发布时间】:2012-04-06 22:30:52
【问题描述】:

我的手机中有一个 android 应用程序,我在其中填充了一些数据,然后我想将这些数据附加到数据库中。所以我打算在我的应用程序中添加一个按钮(短信按钮),按下这个按钮时,数据必须更新到服务器数据库,或者它可以将数据转储到服务器中。所以我想知道我们可以向服务器发送短信吗?如果是,怎么做?
注意:我有一个静态 IP 地址的服务器。

【问题讨论】:

    标签: android sms


    【解决方案1】:

    尝试将数据发布到服务器。

    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
        }
    } 
    

    可以参考Android HttpPost: how to get the result http://www.anddev.org/doing_http_post_with_android-t492.html

    【讨论】:

    • 能否详细说明。我是安卓新手。我想通过手机发送短信。
    【解决方案2】:

    您可以尝试使用 HTTP 请求并让服务器端脚本 (php/java/...) 收集数据并将其放入数据库中。可以使用 JSON(或其变体之一)进行编码。您拥有静态 IP 的事实使这非常容易。

    如果您有数据连接(而且由于您使用的是智能手机,您可能有),您最好使用互联网连接

    【讨论】:

      【解决方案3】:

      当您将 GPRS 调制解调器添加到服务器并在其中插入有效的 SIM 卡时,您可以向该号码发送短信,然后您仍然需要一些服务来读取您的短信并将数据转换/转储到服务器本身.

      【讨论】:

      • 感谢 TimVK 的回复。是否有任何服务或方法可用于从调制解调器读取短信?
      • 我想我试过一次ActiveExperts的软件,但那已经是几年前了。
      猜你喜欢
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      相关资源
      最近更新 更多