How does the Android scanner work?
Does any one开发者_JAVA百科 know how the Android scanner works? Does it work like a barcode scanner? And can it scan anything you program it to? If anyone knows where I could learn more about it, please let me know.
This is what i have done
0.Installed the barcode scanner app.
1.go to the link ...(http://code.google.com/p/zxing/downloads/list)
2.download the latest zip file
3.converted the core folder to jar file and added to my proj as external libraries.(It contains all the necessary code to decode the barcodes).
An do something like this
public final Button.OnClickListener openbrowser = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(INTENT_SCAN);
intent.putExtra(SCAN_MODE, QR_CODE_MODE);
startActivityForResult(intent, REQCODE_SCAN);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
t1 = (TextView) findViewById(R.id.content);
if (requestCode == REQCODE_SCAN) {
t1.setText(data.getStringExtra(SCAN_RESULT));
s = data.getStringExtra(SCAN_RESULT);
try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
startActivity(browserIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
5.This was just to decode the url in barcode. to encode your url into qr code .use qr code generators online like this (http://qrcode.kaywa.com/)
6.the above example was to decode url and open it in browser automatically by passing intent to barcodescanner app previously installed.
If you want to use your own barcode scanner libraries, it takes lot of your time. If your thinking in those lines better explore the ZXING code.
I would personally recommend to use those libraries and write a simple by passing intents. There lot of ways to decode barcodes look at this class
http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java
hope all this helps.
zebra crossing qr code scanning libraries.... http://code.google.com/p/zxing/
Scanner example http://malsandroid.blogspot.com/2010/07/using-barcode-scanner.html
精彩评论