|
ScanningViaIntent
Simple access to barcode scanning in Android, via Intents rather than direct use of project code
How to scan a barcode from another Android application via IntentsManuallyIf the Barcode Scanner is installed on your Android device, you can have it scan for you and return the result, just by sending it an Intent. For example, you can hook up a button to scan a QR code like this: public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}For more options, like scanning a product barcode, or asking Barcode Scanner to encode and display a barcode for you, see this source file: And here's some source from our test app which shows how to use them: IntentIntegratorWe have also begun creating a small library of classes that encapsulate some of the details above. See IntentIntegrator for a possibly easier way to integrate. In particular this will handle the case where Barcode Scanner is not yet installed. Via URLAs of Barcode Scanner v2.6, you can also launch the app from a URL in the Browser. Simple create a hyperlink to http://zxing.appspot.com/scan and Barcode Scanner will offer to launch to handle it. Users can also choose to always have Barcode Scanner open automatically. NOTE: This URL is not meant to serve an actual web page in a browser, it's just a hook to launch a native app. |
Sign in to add a comment
This seems to be more focus on Android. How about the best way of integrating the barcode scanner on a J2ME platform ?
We don't offer any particular support for integration in J2ME, because J2ME doesn't provide any mechanisms for this. The way to proceed there is to reuse the J2ME code and core library we provide.
and what about integration on iPhone? Is the ZXing app registering any URL handler to be called from a web application for example?
Same story I think - iPhone doesn't have a mechanism like Android Intents to pass information between apps. If you mean registering a URL that just opens the Barcodes app, I am not sure how to do that on iPhone (Christian might) but i believe http://zxing.appspot.com/scan does this on Android.
I mean that, registering a URL that just opens the Barcodes app. In the Info.plist of an application you can efine specific URL handlers (or protocols), here it is explained:
http://www.mobileorchard.com/apple-approved-iphone-inter-process-communication/
How do I get the Via URL method working? Going to http://zxing.appspot.com/scan with the android Browser loads the static page telling me the app will load automatically if it is installed. What am I missing?
The idea is, the URL itself delivers some kind of download page. Once installed however, Android understands that the app wants to register to handle the URL. The user is asked instead, on clicking the link, whether to launch the app.
So if I build a webpage that links to http://zxing.appspot.com/scan and someone views it on an android phone it will open the zxing app and then report back the UPC code to the browser?
I have the zxing app installed but when I use the browse to go directly to that url it tells me to install the barcode scanner.
(Let's follow up on the discussion group at http://groups.google.com/group/zxing)
Yes, this works on Android only. Hmm, make sure you have the latest version installed? should pop up and prompt you to open with Barcode Scanner, or with the browser.
Anyway to capture the result when launching via the URL? Maybe populate a javascript object or post the result to a specified URL?
Please ask question at the discussion group: http://groups.google.com/group/zxing Short answer is no, and what you see done with Google Product search is special-cased for that site.