我在手机上有一个安卓应用程序,在其中填写了一些数据,然后我想将这些数据添加到数据库中。所以我计划在我的应用程序中添加一个按钮(短信按钮),当点击该按钮时,数据应该更新到服务器数据库或只需将数据转储到服务器。因此,我想知道我们是否可以向服务器发送短信?如果可以,如何操作?
注意:我有一个具有静态IP地址的服务器。
尝试将数据发布到服务器。
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
}
}
当您将GPRS调制解调器添加到服务器并插入活动SIM卡时,您可以向该号码发送短信,然后仍需要一些服务来读取您的短信并将数据转换/转储到服务器本身。