Skip to content
Create a gist now

Instantly share code, notes, and snippets.

EDIT: No linebreaks I put into this box while typing persist. Bah.
Android ZXing Demo
You can download Eclipse from here:
From top to bottom in Eclipse.
These are the changes I made to the cw-omnibus/Camera/ZXing project files
I did change the names of the package files by right clicking on them-- those changes are reflected in the text below (ex com.launchhouse.demo.zxing.ZXingDemo). The original names of the resources do not match the source material provided here. Right-click to make it so by renaming them in the file hierarchy pane.
I used the Android Developer site to try to not pass on incomplete information about a 'standard' Android app project file hierarchy.
I also screen captured a video-- that may take some time to distill. Link forthcoming.
I want to thank everyone who showed up. I hope you were able to take something away with your for your time. Who should really be thanking you though are the next group-- which will benefit from the obvious shortcomings of the earliest times I have tried to present this subject material.
There are a lot of places for help.
I read on forums, but don't post on forums. I don't have a favorite, I google my problems first.
Then I turn to the android-dev Internet Relay Chat (IRC from way back when, yes. We nerds still use this archaic text messaging system.) channel on the freenode network. I am in a lot of channels on a regular basis and pick at random which I will help in for a bit each day.
Then you all have access to me directly., I will do what I can. I have been given a lot of guidance, and I am starting to feel the burden that I should be giving more back. I'm not helping you for you. I'm offering help to you for me-- so don't feel bad about contacting me.
My initial raw notes follow from here, the files are in their own boxes below.
Install Android SDK
Get the commonsware starter package
// Describe the files and their significance //explanation of common file locations and what they do //explanation of package line inside of the main .java file
// Java OOP basics
class game {
public var noise;
private var unused;
private function bounce(thing) {
//some things are just built into the language
//we will make an assumption that we can get the noise an object makes by asking for it
output = inherentNoise(thing);
return output;
public function doThat(thing) {
this.noise = bounce(thing);
public static function doThis(thing) {
return bounce(thing);
game1 = new game;
echo game1.noise; // will result in a hollow ting sound
echo game::doThis(ball); // will result in a hollow ting sound
// Import the commonsware camera.zxing projects example
give local download URI
provide source download URI in the notes
// For shizzles and giggles change the package name
in the res/values/strings.xml file update the app_name line: "<string name="app_name">Launch House Demo</string>"
It is worth noting that we are blatantly taking someone else's work and removing some of the indication that it was created by someone else.
change the package name in ZXingDemo\src\ from "" to "com.launchhouse.demo.zxing"
Click the containing package that contains the then choose File>Refactor>Rename the package from "" to "com.launchhouse.demo.zxing"
// You just renamed your package!
Let's create an android virtual device.
Window>Android Virtual Device Manager
Click the 'New...' button
Now that you have a Virtual Device to play with.
Select it and start it up.
Go ahead and run your program, there is a green circle with a white 'play' triangle in it.
Click Scan!
It will ask if you want to download the latest BarcodeScanner-- you do. So, do it.
Once downloaded and you can install it. The ZXing barcodescanner.apk will be accessible via the download success notification and the downloads directory. You can use that file to install the BarcodeScanner App.
On the first usage regardless of in your app or out, the ZXing BarcodeScanner app will give you a quick initial page of information about bugfixes and/or new features along with other version information. Once closed you should see the simulated camera screen.
Let's add a button, why not.
We'll eventually send the scanned value to the server. Let's do that via the press of this new button.
Add a button block similar to the previous button block:
android:text="@string/contact" />
Let's talk about linear layout versus -----adaptive layouts-----
So we will mind where we place this block in the XML document.
Let's add a string to go with the button.
Open or switch to res/values/strings.xml and add a line as follows: "<string name="contact">Contact the server!</string>"
We get an error! Let's look at the LogCat.
We do not have the "INTERNET" permission, which needs declared to the user upon installation.
<?xml version="1.0" encoding="utf-8"?>
<!-- I edited a portion of this line from "" to "com.launchhouse.demo.zxing"-->
<manifest xmlns:android=""
<!-- I added the <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="17" /> line to remove the warning
... and summarily took it out.
Explaining putting the chunk of code, contactServer(), that contacted the server in a background asynctask was daunting.
Having the networking in the main thread throws an error that prevents building the .apk.
For whatever reason Eclipse calls it 'building' and not 'compiling'.
<!-- I added the permission line -->
<application android:label="@string/app_name">
<!-- I changed this line, specifically com.launchhouse.demo.zxing -->
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<?xml version="1.0" encoding="utf-8"?>
<!-- res/layout/main.xml -->
<LinearLayout xmlns:android=""
android:orientation="vertical" >
android:text="@string/scan" />
android:layout_height="wrap_content" />
android:background="#FF0000FF" />
android:layout_height="wrap_content" />
<!-- I added these blocks -->
android:background="#FFFF0000" />
android:text="@string/contact" />
android:background="#FF0000FF" />
android:layout_height="wrap_content" />
<?xml version="1.0" encoding="utf-8"?>
<!-- res/values/strings.xml -->
<string name="app_name">Launch House Demo</string>
<string name="scan">Scan!</string>
<string name="contact">Contact the server!</string>
Copyright (c) 2008-2010 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
package com.launchhouse.demo.zxing;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
// I edited this line from "" to "com.launchhouse.demo.zxing.R"
import com.launchhouse.demo.zxing.R;
public class ZXingDemo extends Activity {
TextView format=null;
TextView contents=null;
// I added this
TextView apiReturn=null;
public void onCreate(Bundle savedInstanceState) {
// I added this line
public void doScan(View v) {
(new IntentIntegrator(this)).initiateScan();
// all these lines were added to the commonsware start package START
public void onClick(View v) {
public void contactServer(View v) {
Log.d("TAG", "To The LogCat!");
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("stringdata", contents.getText().toString()));
//nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int responseCode = response.getStatusLine().getStatusCode();
switch(responseCode) {
case 200:
HttpEntity entity = response.getEntity();
if(entity != null) {
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
Log.d("TAG", "To The LogCat! CPE");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("TAG", "To The LogCat! IOE");
//all these lines were added to the commonsware start package END
public void onActivityResult(int request, int result, Intent i) {
IntentResult scan=IntentIntegrator.parseActivityResult(request, result, i);
if (scan!=null) {
public void onSaveInstanceState(Bundle state) {
state.putString("format", format.getText().toString());
state.putString("contents", contents.getText().toString());
// I added this line
state.putString("apiReturn", apiReturn.getText().toString());
public void onRestoreInstanceState(Bundle state) {
// I added this line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.