How does the Android scanner work? - android

Does any one know how the Android scanner works? Does it work like a barcode scanner? And can it scan anything you program it to? If anyone knows where I could learn more about it, please let me know.

This is what i have done
0.Installed the barcode scanner app.
1.go to the link ...(http://code.google.com/p/zxing/downloads/list)
2.download the latest zip file
3.converted the core folder to jar file and added to my proj as external libraries.(It contains all the necessary code to decode the barcodes).
An do something like this
public final Button.OnClickListener openbrowser = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(INTENT_SCAN);
intent.putExtra(SCAN_MODE, QR_CODE_MODE);
startActivityForResult(intent, REQCODE_SCAN);
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
t1 = (TextView) findViewById(R.id.content);
if (requestCode == REQCODE_SCAN) {
t1.setText(data.getStringExtra(SCAN_RESULT));
s = data.getStringExtra(SCAN_RESULT);
try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
startActivity(browserIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
5.This was just to decode the url in barcode. to encode your url into qr code .use qr code generators online like this (http://qrcode.kaywa.com/)
6.the above example was to decode url and open it in browser automatically by passing intent to barcodescanner app previously installed.
If you want to use your own barcode scanner libraries, it takes lot of your time. If your thinking in those lines better explore the ZXING code.
I would personally recommend to use those libraries and write a simple by passing intents. There lot of ways to decode barcodes look at this class
http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java
hope all this helps.
zebra crossing qr code scanning libraries....
http://code.google.com/p/zxing/
Scanner example
http://malsandroid.blogspot.com/2010/07/using-barcode-scanner.html

Related

ARcore and mobile-vision

I need to create an android app doing mainly two things.
1) Detect price and barcode
2) Creating AR content around the detected price/barcode
For the detection part, I use google mobile-vision and for the AR part I use ARcore. The problem I have is that Arcore doesnt allow auto focus so I dont have a good enough resolution to read the prices or bar codes.
So I was wondering if there was a standard way to do text recognition and AR in the same app.
Thank you.
You can implement them in the same app, on different activities. if you are using the mobile vision API. you can set the start the intent for detection with startActivityForResult and when the result is returned. you can Implement a transistion in the onActivityResult part. Since the AR depends on the detected data you can pass the information to the AR activity using putExtra. use this as a template
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(DetectActivity.this, ScanActivity.class);
startActivityForResult(i, REQUEST_CODE);
}
});
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
if (data != null) {
final Barcode barcode = data.getParcelableExtra("barcode");
String rslt=barcode.displayValue;
Intent intent =new Intent(DetectActivity.this, ArActivity.class);
intent.putExtra("link", rslt);
startActivity(intent);
finish();
Hope this helps,
ScanActivity is the normal Camera View SurfaceView activity that mobile vision uses
I haven't used ARcore, but have done a reasonable amount of detection. This was mostly done using a surface view extension showing and initialising a camera1 api view with detection interface and callbacks.
It is difficult to tell what might be going wrong without any code available or how you have gone about this, any chance you could provide some?

Barcode app Scan result display on screen

I am trying to make a barcode scanning app. I am stuck at the point where I am able to scan the barcode but now I want to show the barcode image along with decoded barcode number and other details on the screen and then provide a button to proceed to next screen. How should I go about it? I am unable to understand should I call an intent to new activity or the layout view. If I call the new activity, how do I pass the barcode that's decoded and other details to new activity?
Help.
Want something like this after scanning a barcode:
you can get and use that barcode anywhere, as:
uid is a textview where i have added the result from ZXing (Zebra Crossing) library activity.:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
Log.e("test 1",String.valueOf(requestCode));
if (resultCode == RESULT_OK) {
Log.e("test 2",intent.getStringExtra("SCAN_RESULT_FORMAT"));
Log.e("test 3",intent.getStringExtra("SCAN_RESULT"));
Toast.makeText(getApplicationContext(), intent.getStringExtra("SCAN_RESULT"), Toast.LENGTH_LONG).show();
uid.setText(intent.getStringExtra("SCAN_RESULT")) ;
} else if (resultCode == RESULT_CANCELED) {
Log.e("test 4",String.valueOf(requestCode));
}
}
}
Over Image you are seeing in sample image is a generated barcode not a actual picture captured from the camera.
For this you can use iText is a great Java PDF library. They also have an API for creating barcodes. You don't need to be creating a PDF to use it.
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(codeEAN.EAN13);
codeEAN.setCode("9780201615883");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);

Android Zxing (barcode library). How to change the after scan intent

I am developing an Android application, I need to embed the Zxing scanner. The application should allow the user to scan a QR Code and then store the QR code ID of the product and parse it from an XML file. As yet, I have used the simple code:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage(getPackageName());
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
What this code does is, scans the product and bring me back to the previous screen of my app. I haven't included the entire library from Zxing as I wanted the Barcode scanner to handle it, but it seems I have to do more than I already have done.
You need to make an onActivityResult method that will get the callback once barcode scanner is done. Inside there you will handle the code string and do whatever you like with it.
/*Here is where we come back after the Barcode Scanner is done*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
// contents contains whatever the code was
String contents = intent.getStringExtra("SCAN_RESULT");
// Format contains the type of code i.e. UPC, EAN, QRCode etc...
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
Log.i("TAG",format + "\t" + contents);
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel. If the user presses 'back' before a code is scanned.
Log.i("TAG","Canceled");
}
}
}
This example just logs the results, you'll need to expand upon it to do whatever you want with the info you get back from the scanner.
Better still, use the IntentIntegrator class supplied with the project. It wraps up all the details listed here and its documentation already tells you exactly how to integrate it into your app. It deals with things for you like getting the app installed if not already.

How to Retrieve product id from bar code?

I have used the same way of Zxing Intent to open scanner from my application. But my application just opens scanner and does nothing. Also, I am getting some FileNotfoundException.
Do I have to add any permission in manifest?
This is my class where I use Intent:
public class BarCodes extends Activity {
/** Called when the activity is first created. */
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok;
ok=(Button) findViewById(R.id.b1);
ok.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE","QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
System.out.println("SSSSSSSSSSSSS");
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
System.out.println("contentsssssssssssssssssssssss" + contents);
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
Also LogCat is here:
java.lang.RunTimeException:Unable to instantiate activity componentInfo{com.pkg.BarCode...}
caused by : java.lang.classNotFoundException:com.pkg.Scan in loader dalvik.System Loader…
What might be the problem??
This question is answered in more detail here and here. As to why you are getting the FileNotFoundException you'd have to provide more detail, such as the code for which you are invoking the Zxing intent as well as the logcat stack trace.
Your error is nothing to do with the project. Android is saying it is unable to find your class, com.pkg.Scan. You'll have to fix your project setup.
However I'd further suggest that you not try to write your own code, but use the code provided by the project to integrate via Intent.
Steps:
Install Apache Ant (http://www.youtube.com/watch?v=XJmndRfb1TU , this video will help you to do that) and also refer http://ant.apache.org/ for more info and download ant
Download the ZXing source from ZXing homepage and extract it (For More info :http://code.google.com/p/zxing/source/browse/trunk/android/)
With the use of Windows Commandline (Run->CMD) navigate to the extracted directory
Type 'ant -f core/build.xml' or 'ant -f android/build.xml'
Enter Eclipse -> new Android Project
Right-click project folder -> Properties -> Java Build Path -> Library -> Add External JARs
If the Barcode Scanner is installed on your Android device, you can have it scan for you and return the result, just by sending it an Intent. For example, you can hook up a button to scan a QR code in this way
It will have the product code Stored in the String value 'contents'
Have fun with BarCode by implementing it in your own way :-)

Basic ZXING library application

I am trying to produce
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_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");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
Using the libraries therefore not needing to install the software, I have had a look at the application that comes with it, and added CaptureActivity.java to my project to see if I can locate the core scanning loop but it kept just requiring more and more files (ended up with about 28 in total) and after I had no errors it still didn't work.
I am not looking into doing anything fancy, just on a button click open the capture layout, scan a code, return the code.
There are a few examples on how to decode local files but not the actual scanning side of it to detect a actual barcode.
So, what I help with is embedding the scanning code
Thanks
I think you're mixing up two things. The code you have shows you are trying to integrate via Intent, in which case you do not need any project code in your application at all.
The source in android/ is a complete stand-alone app (Barcode Scanner) and it is not written for you to copy (although the Apache License permits it). What you are doing is not supported, recommended, or encouraged -- integrating via Intent is much easier.
Write your own app, perhaps looking to the Android source code for inspiration, and that uses the core/ library for scanning. The core scanning happens in DecodeThread.

Categories

Resources