【发布时间】:2016-06-01 21:46:26
【问题描述】:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == SCANNER_REQUEST_CODE) {
// Handle scan intent
if (resultCode == Activity.RESULT_OK) {
// Handle successful scan
String contents = intent.getStringExtra("SCAN_RESULT");
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
Integer orientation = (intentOrientation == Integer.MIN_VALUE) ? null : intentOrientation;
String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
mBarcodeEdit.setText(contents + "\n\n" + formatName);
tvScanResults.setText(contents + "\n\n" + formatName);
} else if (resultCode == Activity.RESULT_CANCELED) {
// Handle cancel
}
} else {
// Handle other intents
}
}
现在我将扫描的条形码放入edittext 和textview 中,但我想将结果上传到服务器。我将在下面发布 AsyncTask 模块:
public void send1(View v){
new Send().execute();
}
class Send extends AsyncTask<String, Void,Void > {
HttpClient httpclient;
HttpPost httppost;
String msg = mBarcodeEdit.getText().toString().trim();
protected Void doInBackground(String... urls) {
// TODO Auto-generated method stub
// get the message from the message text box
// String msg = mBarcodeEdit.getText().toString().trim();
//Toast.makeText(getBaseContext(),"u clicked mee",Toast.LENGTH_SHORT).show();
// make sure the fields are not empty
if (msg.length()>0)
{
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://yourwebsite.com/yourPhpScript.php"); // sever id
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("message", msg));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
else
{
// display message if text fields are empty
//Toast.makeText(getBaseContext(),"All field are required",Toast.LENGTH_SHORT).show();
}
return null;
}}
protected void onProgressUpdate(Void... progress) {
}
protected void onPostExecute(Void result) {
mBarcodeEdit.setText(""); // clear text box
}
}
【问题讨论】:
-
@KNeerajLal 不,那部分完全不同,我尝试实现它,但它没有给我所需的解决方案,我只想知道如何从编辑文本中检索数据并将其发送到服务器
-
您在这样做时遇到了什么问题?
标签: java android android-layout android-studio android-asynctask