Android Developers

Home / Android Developers

For Android Developers

This page describes how to use services provided by QR Droid in your own apps. This way, you can allow your users to Scan, Decode or Generate any QR code. It only requires a few lines of code and your users won’t even realize you’re using a 3rd-party app (QR Droid) to do it.

Jump to:  Structure  |  Scan  |  Decode  |   Encode  |  Demo App

 

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 indata.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.php }

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

 

Scan

  • 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

 

Decode

  • Action: You must use this action: la.droid.qr.decode

Intent qrDroid = new Intent( “la.droid.qr.decode” );

  • Mandatory parameter: You MUST provide full path of image to be decoded by seting extra “la.droid.qr.image“. This image must be PNG, JPG or GIF and must contain a QR code. It can be a local path (ex: /sdcard/yourApp/qr.png) or a remote URL (ex: http://qrdroid.com/market/qr.png)

qrDroid.putExtra(“la.droid.qr.image”, “http://qrdroid.com/market/qr.png”);

  • Optional parameter: Exactly as Scan service, you can optionally set this parameter (default is false). Please read “Optional parameter” under “Scan“.

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/Decode.java

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

 

Encode (Generate)

  • Action: You must use this action: la.droid.qr.encode

Intent qrDroid = new Intent( “la.droid.qr.encode” );

  • Mandatory parameter: You MUST provide text to be encoded (QR code contents) by seting extra “la.droid.qr.code“.

qrDroid.putExtra(“la.droid.qr.code”, “This will be QR code content”);

  • Optional parameter “size”: By default, QR code size will be automatic, according to with of screen of device. If you want to override this, you can set “la.droid.qr.size” in pixels.

qrDroid.putExtra( “la.droid.qr.size” , 150);

  • Optional parameter “image”: By default, QR Droid will return to you a full path of generated QR code using Google API, so no image will be really generated and result will start with http://chart.apis.google.com/chart. If you prefer, you can set parameter “la.droid.qr.image” to make QR Droid create this image in user’s SD card and return a local path (ex: /sdcard/QrDroid/tmp/QrDroid_123.png)

qrDroid.putExtra( “la.droid.qr.image” , true);

  • Call:

startActivityForResult(qrDroid, 0);

  • Result: Inside onActivityResult(int requestCode, int resultCode, Intent data), you must read result as String. It will contain a remote URL or a local path.

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/Encode.java

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

 

Demo App

Download a simple app that shows how to use these services. You can get it from the Android Market or direct download it:

http://market.android.com/details?id=la.droid.qr.services

http://droid.la/apk/qr-s/

After you test it, download full source code here:

http://qrdroid.com/QrDroidServices.zip

If you have any question about how to use these services in your app, don’t hesitate to write to info@droidla.com.