I had an issue with the parseActivityForResult arguments. I got this to work:
package JMA.BarCodeScanner;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class JMABarcodeScannerActivity extends Activity {
Button captureButton;
TextView tvContents;
TextView tvFormat;
Activity activity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
activity = this;
captureButton = (Button)findViewById(R.id.capture);
captureButton.setOnClickListener(listener);
tvContents = (TextView)findViewById(R.id.tvContents);
tvFormat = (TextView)findViewById(R.id.tvFormat);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
switch (requestCode)
{
case IntentIntegrator.REQUEST_CODE:
if (resultCode == Activity.RESULT_OK)
{
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (intentResult != null)
{
String contents = intentResult.getContents();
String format = intentResult.getFormatName();
tvContents.setText(contents.toString());
tvFormat.setText(format.toString());
//this.elemQuery.setText(contents);
//this.resume = false;
Log.d("SEARCH_EAN", "OK, EAN: " + contents + ", FORMAT: " + format);
} else {
Log.e("SEARCH_EAN", "IntentResult je NULL!");
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.e("SEARCH_EAN", "CANCEL");
}
}
}
private View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.initiateScan();
}
};
}
Latyout for Activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Take a Picture"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tvContents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tvFormat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>