我正在开发一个android应用程序,用于收集数据,然后将其发送到Web目录。来自Android应用程序的数据 - > MYSQL
因此,我们可以说想要在手机上收集数据,然后点击一个按钮后,将所有数据作为文件或流发送到在线目录。它甚至不需要得到答复 - 虽然将来确认会很方便。
如何被发送到数据到mysql
提交我的代码如下
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
InputStream inputStream;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
nameValuePairs.add(new BasicNameValuePair("Lat","19.80"));
nameValuePairs.add(new BasicNameValuePair("Lon","13.22"));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost/guestfeedback/connection.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
Log.i("postData", response.getStatusLine().toString());
}catch (Exception e) {
// TODO: handle exception
}
}
我想从android发送3个不同的值给mysql。 – Piyush
我知道你想要做什么。我问[你还试过了什么](http://mattgemmell.com/2008/12/08/what-have-you-tried/)来完成这个任务。 :) – 2011-09-16 04:10:44
我发布我的代码如上 – Piyush