应用程序在Android上的Zxing条码扫描器应用程序崩溃

时间:2014-02-11 07:35:08

标签: android android-intent zxing

我正在为客户端开发一个Android应用程序。应用程序中的一个小模块是用户可以扫描条形码。成功执行扫描后,将从数据库中获取详细信息.i将zxingbarcode扫描仪集成到我的Android应用程序中。一切正常。如果用户按下后退按钮应用程序崩溃,则执行条形扫描过程。有时扫描需要花费更多时间来设置设备正确聚焦。当我们退出而没有得到结果时会出现问题。

请帮助...提前谢谢 代码如下:

public class MainActivity extends Activity implements OnClickListener {

    private Button scanBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        scanBtn = (Button)findViewById(R.id.scan_button);
        scanBtn.setOnClickListener(this);
    }
    public void onClick(View v){
        //check for scan button
        if(v.getId()==R.id.scan_button){
            //instantiate ZXing integration class
            IntentIntegrator scanIntegrator = new IntentIntegrator(this);
            //start scanning
            scanIntegrator.initiateScan();
        }
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        IntentResult scanningResult =      IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        //check we have a valid result
        if (scanningResult != null) {
            //get content from Intent Result
            String scanContent = scanningResult.getContents();
            Log.d("scanContent", scanContent);

            Intent i = new Intent(getBaseContext(),CustomerDetailDisplay.class);
            i.putExtra("scanContent", scanContent);
            Log.d("scanContent", scanContent);
            startActivity(i);
        }
        else{

            Toast toast = Toast.makeText(getApplicationContext(), 
                    "No scan data received!", Toast.LENGTH_SHORT);
            toast.show();
        }
    }

}

0 个答案:

没有答案