I want to integrate Zxing in a android project (I'm a beginner).
I have seen that the way described here http://bit.ly/nBszrL is discouraged and that the best way to do it is through Intents as said in this post http://bit.ly/o29Uma
p.s : I don't want the barcode scanner installed on my device
I have Included on my project the required class : http://bit.ly/16pKMKx
my test code :
package com.example.barcodescanner;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final int REQUEST_BARCODE = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// when my button is clicked
public void scanBarCode(View view) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, REQUEST_BARCODE);
Toast toast = Toast.makeText(this, "Start scanning Barcode", Toast.LENGTH_SHORT);
toast.show();
}
}
and I really don't understand how to do it by this way : http://bit.ly/18v7K2O (I really don't get it and that's what I want to use)
Do you have any idea about how to do it ?
Thank you.
The Android system was built to so that people could write apps that do one particular thing well and other developers could use them when they need to. Barcode scanning is a great example. ZXing makes a great scanner and lets other apps use it via Intents. Basically you tell the OS that you want to scan a barcode and ZXing says, "Yes, I can do that!" They scan the barcode and return the information to you. The great thing about doing it this way is that you don't have to worry about when they update their stuff. The user just gets notified that it's updated and you get to use the latest and greatest. The one potential downside is that the user has another app on their phone but I don't really see that as a draw back. To do it this way you really only need the two files you linked to and then you just place this in your code To start the scan:
And this bit gets the answer from the barcode scanner:
Your only other option is to pull down all of the code for the barcode scanner and lump that into your project and then figure out how it all works and where you need to tie in to bring it into your app. Then you'll have to do that all over again every time ZXing makes an update. It's a mess!