creating bar code scanner in android application
i am assuming that you are using Eclipse for the development. Here is very simple way to add the barcode scanner to use in your own applications.
create new project and add these assets into your src folder. You can also download it from zxing. In your main activity add the below line of code where you want to scan something.
IntentIntegrator.initiateScan(this);
And, put the below function in the same activity
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch(requestCode){
case IntentIntegrator.REQUEST_CODE: {
if (resultCode != RESULT_CANCELED){
IntentResult scanResult=IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(scanResult != null){
String upc=scanResult.getContents();
//put whatever you want to do with the code her
TextView tv=new TextView(this);
tv.setText(upc);
setContentView(tv);
}
}
break;
}
}
}
in this example it will just show the code in a text view after scanning is completed. This is just calling bar code scanner using the intent. This means if we already installed the bar code scanner in the device our application can contact with the installed bar code scanner. In order to integrate the complete bar code scanner in our own application we need to add the zxing library to our application.
i am assuming that you are using Eclipse for the development. Here is very simple way to add the barcode scanner to use in your own applications.
create new project and add these assets into your src folder. You can also download it from zxing. In your main activity add the below line of code where you want to scan something.
IntentIntegrator.initiateScan(this);
And, put the below function in the same activity
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch(requestCode){
case IntentIntegrator.REQUEST_CODE: {
if (resultCode != RESULT_CANCELED){
IntentResult scanResult=IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(scanResult != null){
String upc=scanResult.getContents();
//put whatever you want to do with the code her
TextView tv=new TextView(this);
tv.setText(upc);
setContentView(tv);
}
}
break;
}
}
}
in this example it will just show the code in a text view after scanning is completed. This is just calling bar code scanner using the intent. This means if we already installed the bar code scanner in the device our application can contact with the installed bar code scanner. In order to integrate the complete bar code scanner in our own application we need to add the zxing library to our application.