Basic ZXING library application - android

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.

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?

Could not get audio file extension from ACTION_OPEN_DOCUMENT intent in Android 5.0.2

In one of my android projects I'm facing the following issue on a Samsung Tablet with Android 5.0.2: From a Fragment, the user can start to choose a file:
private static final int REQUEST_CHOOSE_FILE = 1;
...
private void chooseFile() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
this.startActivityForResult(intent, REQUEST_CHOOSE_FILE);
}
The activity result is handled via
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CHOOSE_FILE && resultCode == Activity.RESULT_OK && data != null) {
Uri uri = data.getData();
String path = Util.getPath(this.getBaseActivity().getApplicationContext(), uri);
...
}
}
with Util.getPath(...) taken from Get real path from URI, Android KitKat new storage access framework
This works fine for nearly everything - but not for files taken from the "Audio" link in the left part of the filechooser. In this case I'm not able to determine the file extension with my helper function. Everything I get is the name of the file...
I'm a bit stuck, especially because the filechooser isn't showing the extension, too.
Does anyone know this issue and could give me a hint to work around it?
This works fine for nearly everything
No, it does not. It works for a small subset of providers, and fewer with each passing month.
Does anyone know this issue
The issue is that you are relying upon intrinsically unreliable code.
could give me a hint to work around it?
If you want to use the content associated with a Uri, use a ContentResolver. In particular, if you want to know the MIME type of the content, use getType() on ContentResolver. From there, you can attempt to come up with a relevant file extension, such as through MimeTypeMap.

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 does the Android scanner work?

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

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 :-)

Categories

Resources