The G1 came out this week and I have been putting it through the paces. I really like the seamless transition between developing with the emulator and developing on the device. I think overall it is a very strong first device for Android, but I think that normal users may not recognize some of the more powerful features of the platform.

The Intent system allows for applications and activities to interact with each other, so that you can have applications using the features of other applications. I think this is a really interesting concept and think it could lead to a less application-centric view of phone operation towards a more feature-centric view. Instead of developing an entire application, developers can develop specific features that perform a very specific task. These features can be used by other applications to create new and interesting functionality.

I think the best example of this concept is Barcode Scanner. Barcode Scanner is the application specific manifestation of ZXing which I blogged about previously. Installing it lets you scan bar and QR Codes and lets you perform search actions or interact with the results(like an e-mail address or phone number). The two shopping applications CompareAnywhere and ShopSavvy use the ZXing library themselves for doing barcode scanning, but they include the ZXing library as part of their application bundle.

In my previous entry I mentioned that I would like to see specific Intents that let you use the encoding and decoding ability of ZXing from other applications and the ZXing team responded that the latest build had this exact functionality! Now all you have to do is install Barcode Scanner on your phone and your applications can take advantage of its features. Specifically, it provides Intents that allow your application to use the encoding and decoding functionality. The Intent mechanism makes it almost too simple to integrate this functionality into your application.

Encoding – “com.google.zxing.client.android.ENCODE”

To encode a string into a QR Code Simply create an Intent with the Decode action specified, two string extras specifying the Type and Data and call startActivity():


Intent intent = new Intent("com.google.zxing.client.android.ENCODE");
				intent.addCategory(Intent.CATEGORY_DEFAULT);
				intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
				intent.putExtra("ENCODE_DATA","HELLO WORLD");
startActivity(intent);

The string values for the Intents and the extras values can be found in the Intents and Content classes in the ZXing source code.

Decoding – “com.google.zxing.client.android.SCAN”

Bringing up the decoding camera interface is just as easy as encoding with the added step of having it return the decoded value of the barcode to our main application.


Intent intent = new Intent("com.google.zxing.client.android.SCAN");
				intent.addCategory(Intent.CATEGORY_DEFAULT);
				startActivityForResult(tent,0);

The big difference here is that we are using startActivityForResult which will allow the scanning activity to return the results of the scan back to our app. In the Activity that launched the decode intent we can extract the results of the scan in the onActivityResult method by simply accessing the string extra “SCAN_RESULT”.


data.getStringExtra("SCAN_RESULT");


You can now use these features to do all kinds of interesting things. I am currently interested in transferring data between phones by encoding the data in a QR code and having the other phone retrieve it by simply pointing it at the other camera’s screen. You could also encode movie ticket information into a QR code and have it displayed on the phone so it can be scanned at the theater.

I hope this post showed you how useful Barcode Scanner can be for your application and it’s users. Now if someone could do something about the reviewers in the android app store…..

Posted on October 23rd, 2008 | filed under Uncategorized | Trackback |

6 Comments

  1. Daniel Switkin:

    Thanks for the post, it’s exactly on the money. We hope people will be able to leverage barcode scanning to do new and creative things.

    You can have a look at the android test app for more examples of sending these intents:

    http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java

    Cheers,
    Daniel

  2. admin:

    I think the main problem will be trying to keep up with dependencies with other apps. Telling users which applications they need to have installed for your application to work properly. As it is I think a lot of people are confused about why they would need Barcode scanner installed when they have one of the other two installed. Maybe some kind of -include-dependencies setting in the manifest?

  3. Lettura BarCode da fotocamera - Forum Android Italiano:

    [...] principale del codice che ho scaricato, mentre invece basta lanciare come indica in questa pagina: a walking city Blog Archive Qr Codes Made Even Easier With Android E funziona perfettamente e in pochissime righe di codice. Grazie Azatoth per la dritta!!! [...]

  4. Konstantin:

    Hi,

    how can I encode byte array?
    I’ve unsuccessful tried with

    private void encodeBarcode(String type, Bundle data) {
    Intent intent = new Intent("com.google.zxing.client.android.ENCODE");
    intent.putExtra("ENCODE_TYPE", type);
    intent.putExtra("ENCODE_DATA", data);
    startActivity(intent);
    }

    Bundle bundle = new Bundle();
    String str = "BLA";
    bundle.putByteArray(meal, myByteArray);
    encodeBarcode("TYPE", bundle);

    Wich type is valid (for encodeBarcode)?
    Wich type must I set for byte array?
    Can byte array be encoded?

  5. Konstantin:

    Sorry

    bundle.putByteArray(str, myByteArray);

  6. Qr Codes With Android « erics2011:

    [...] Original Links: http://awalkingcity.com/blog/2008/10/23/qr-codes-made-even-easier-with-android/ [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>