I am using the following to scan barcode lines.
private Camera mCamera;
private CameraPreview mPreview;
public static final int MEDIA_TYPE_IMAGE = 1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.newmain);
Button captureButton = (Button) findViewById(R.id.button_capture);
// Create an instance of Camera
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
final PictureCallback mPicture = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
Intent intent = new Intent("http://zxing.appspot.com/scan");
// Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
captureButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent("http://zxing.appspot.com/scan");
// Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
// get an image from the camera
// System.out.println("Photo Taking!");
// mCamera.takePicture(null, null, mPicture);
}
});
}
Then i am using the following Method to pass the intent to zxing sdk..
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == 0)
{
TextView tvStatus=(TextView)findViewById(R.id.tvStatus);
TextView tvResult=(TextView)findViewById(R.id.tvResult);
if (resultCode == RESULT_OK)
{
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
tvStatus.setText(intent.getStringExtra(format));
tvResult.setText(intent.getStringExtra(contents));
Toast.makeText(getApplicationContext(), "Content:" + contents + " Format:" + format , Toast.LENGTH_LONG).show();
}
else if (resultCode == RESULT_CANCELED)
{
tvStatus.setText("Press a button to start a scan.");
tvResult.setText("Scan cancelled.");
}
}
}
But i am not able to put camera focus on barcode lines.. I would appreciate, if i get some help on how to focus camera on barcode lines, so that i can pass the intent to zxing sdk.. Also, comments on Some Android sdk to scan barcode lines would be appreciated.. Thanx in advance..
Why do you want to take a picture and send it to zxing? You can directly ask Zxing app to open camera and read bar code. See my answer here.