开发者

creating listview and intent to barcode scanner and return result without displaying and send result data to webserver

I am trying to create a listview through resource and each would open the barcode scanner(using android integrate) and return the result without displaying and send the data result to the webserver(By the way, I have succeeded to send a data to webserver as text file and would like to know how to grab that data from the barcode without displaying and send the data result to the webserver as text file). I am having problems trying to succeed in this step. (android 1.5 device, project is 2.2 with sdk 3 using eclipse)

string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MainActivity!</string>
<string name="app_name">company</string>
<string-array name="customer_service_group">
<item>Start Trip</item>
<item>Clock In</item>
<item>Customer Svc</item>
<item>Independent Inspection</item>
<item>Pick Up</item>
<item>Log Out</item>
</string-array>
</resources>

MainActivity.java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

    String[]Customer;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String[] Customer = getResources().getStringArray(R.array.customer_service_group);
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, Customer));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
            // When clicked, show a toast with the TextView text
            Intent i = new Intent("com.merrill.IntentIntegrator");
            startActivityForResult(i开发者_开发知识库, 1);
          }

        });}

    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (requestCode == request_Code) {
            if (resultCode == RESULT_OK) { 
                ------not sure what to put here-----
    }
        }
    }
}


Here is some sample code that should get started receiving the result from BarcodeScanner intent:

/*Here is where we come back after the Barcode Scanner is done*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            // contents contains whatever the code was
            String contents = intent.getStringExtra("SCAN_RESULT");

            // Format contains the type of code i.e. UPC, EAN, QRCode etc...
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

            // Handle successful scan. In this example I just put the results into the TextView
            resultsTxt.setText(format + "\n" + contents);
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel. If the user presses 'back' before a code is scanned.
            resultsTxt.setText("Canceled");
        }
    }
}

Edit: instead of this line

resultsTxt.setText(format + "\n" + contents);

change it to send contents to your server. If you have a method set up for interacting with your server then it would be something like

sendDataToServer(contents);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜