带有outpan数据库的条码扫描器

时间:2014-08-18 07:26:35

标签: java android barcode

我想在android中开发一个条码扫描器应用程序,我尝试使用zxing库。 zxing扫描器非常好地读取条形码然后通过谷歌要求用户进行网络搜索或产品搜索并显示谷歌搜索结果。 这是我到目前为止所做的事情:

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class ScanCodeActivity extends Activity {

    private Button scan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scancodelayout);

        scan= (Button)findViewById(R.id.scan_button);

        Button scanBtn  = (Button)findViewById(R.id.scan_button);
        final TextView  formatTxt = (TextView)findViewById(R.id.scan_format);
        final TextView contentTxt = (TextView)findViewById(R.id.scan_content);

        scanBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentIntegrator scanIntegrator = new IntentIntegrator(ScanCodeActivity.this);
                scanIntegrator.initiateScan();
            }
        });
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
           if (requestCode == 0) {
               IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
               if (resultCode == RESULT_OK) {
                   if (scanningResult != null) {
                       final TextView  formatTxt = (TextView)findViewById(R.id.scan_format);
                       final TextView contentTxt = (TextView)findViewById(R.id.scan_content);
                       String scanContent = scanningResult.getContents();
                       String scanFormat = scanningResult.getFormatName();
                       Toast toast = Toast.makeText(this, "Content:" + scanContent + " Format:" + scanFormat , Toast.LENGTH_LONG);

                       formatTxt.setText("FORMAT: " + scanFormat);
                       contentTxt.setText("CONTENT: " + scanContent);
                     //we have a result
                     }
                   else{
                        Toast toast = Toast.makeText(getApplicationContext(), 
                            "No scan data received!", Toast.LENGTH_SHORT);
                        toast.show();
                    }
               } else if (resultCode == RESULT_CANCELED) {
                  // Handle cancel
                  Log.i("App","Scan unsuccessful");
               }
         }
      }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

我想要实现的是我想查询非商业数据库。我找到了这个链接:

http://www.outpan.com/developers-get-product-data.php

谁能告诉我如何在android中使用它? 我想扫描一个特定的代码并用它查询outpan数据库,以便我将结果解析为Strings并在我的Android应用程序中显示它们。用户将知道条形码代表哪种产品..

0 个答案:

没有答案