Scan a QR code

Action: 
la.droid.qr.scan
Input: 
None
Output: 
Contents of QR code as String, under extra "la.droid.qr.result"

Scan a QR code with QR Droid.

Structure

First, I’ll give a general idea of how QR Droid services are structured and how they must be called. To use QR Droid services, you must simply create an Intent with one of these actions:
la.droid.qr.scan
la.droid.qr.encode
la.droid.qr.decode

(Note that QR Droid package is “la.droid.qr“, so that’s why all actions have that prefix)

You call one of this actions in 3 steps:
Create a new Intent. For example: Intent qrDroid = new Intent( “la.droid.qr.scan” );
Optionally, set any extra parameter: qrDroid.putExtra( “la.droid.qr.complete” , true);
Finally, start activity and wait fo a result: startActivityForResult(qrDroid, 0);

You must also override onActivityResult(int, int, Intent) to be able to receive result from QR Droid. Always, result is stored in data.getExtras().getString( “la.droid.qr.result” );

When calling activity, you must consider that user could not have QR Droid nor QR Droid Private installed in his device. You can get a list of installed apps to check if QR Droid is one of them, or simply do something like this:

try {
startActivityForResult(qrDroid, ACTIVITY_RESULT_QR_DRDROID);
} catch (ActivityNotFoundException activity) {
//TODO: Ask user to get “QR Droid” or “QR Droid Private” from http://qrdroid.com/get
}

(Previous code is included in sample app, which you can download at bottom of this page)

Scan Intent

Action: To call Scan activity from QR Droid, you must create an Intent with action: la.droid.qr.scan

Intent qrDroid = new Intent( “la.droid.qr.scan” );
Optional parameter: This Activity has one optional parameter which specifies whether you want to receive full, unprocessed QR code contents; or only a visible, processed representation (this last one is default behavior). For example, a simple QR code with a phone number contains this “tel:+1234567“. By default, QR Droid will only send you back “+1234567″. If you want to receive full data (“tel:+1234567″), you must add this parameter:

qrDroid.putExtra( “la.droid.qr.complete” , true);
Call:

startActivityForResult(qrDroid, 0);
Result: Inside onActivityResult(int requestCode, int resultCode, Intent data), you must read result as String, like this:

String result = data.getExtras().getString(“la.droid.qr.result”);

Here, you can check out a little example of an Activity that calls QR Droid Scan service and reads content back.

http://qrdroid.com/Scan.java

It uses a few constants defined here: http://qrdroid.com/Services.java