Jump to content

ZXing via intents (Android SDK) - can anyone help with my code?


Guest glossywhite

Recommended Posts

Guest glossywhite

Hi. I'm accessing "ZXing" barcode scanner via intents with the SDK & Eclipse. This code works, right up to when I expect the TextView to be updated with the scanned data in a String... and then it crashes.

Any ideas where I've messed up?

package com.matt.barcode;


import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;


public class ScanQR extends Activity implements OnClickListener {

	public Button scanCode;

	public TextView showScan;


	/** Called when the activity is first created. */

	@Override

	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		scanCode = (Button)findViewById(R.id.scanCode);

		scanCode.setOnClickListener(this);




	}


	@Override

	public void onClick(View v) {

		Intent intent = new Intent("com.google.zxing.client.android.SCAN");

		intent.setPackage("com.google.zxing.client.android");


		intent.putExtra("SCAN_MODE","PRODUCT_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");

				showScan.setText(contents);

				String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

				// Handle successful scan

			} else if (resultCode == RESULT_CANCELED) {

				showScan.setText("Please try again");

				// Handle cancel

		   }

		}

	}

}

Muchly thankful :)

Edited by glossywhite
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.