I have posted a question before and got response regarding Barcode scanning in ZXing.
Currently i have run the barcode scanner app code, that is given in the source(/android/) using this post
My objective is to scan a barcode in my app. Since zxing is open source as told by the authors, i need to customize the scanner app raw code in my app. I found many files like WifiActivity and all. I dont know whether all the files are required to scan a barcode.
Now i want to extract the necessary and required files to decode using the camera captured image. Is it possible to extract the parts? If yes, can anyone help me in doing this by referring any links or steps. Thanks for all your useful posts and great responses. Sorry for my bad english.
what exactly are you trying to achieve? Do you want to edit and enhance the ZXing Source/App or want to use this library in your App for scanning.
For scanning you could invoke the activity for the scan result like following:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
try {
startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
//Do something here
}
After scan u will receive the result in onActivityResult method:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_CODE) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
I did something similar to this, but I only wanted the QR generation part of the zxing project. So I found the relevant call (maybe something like Bitmap b = zx.genQRCode() or whatever) and copied that java file into my project.
Compile and BAM - you get a ton of compile errors. At the point you just start copying other referenced files into your project until you don't get any more compile errors.
Don't forget to include proper attribution in your app - see this FAQ.
Related
I am using Intent(Intent.ActionOpenDocument) and OnActivityResult() fine in my Android mobile app. (Targeting Android 10, API 29). The user selects an audio file and the app plays the file fine. Ths user is able to select a file from anywhere on their device.
I would like to display the name of the file that is playing in the UI. How do I grab the filename?
In OnActivityResult, this: ReturnedIntent.Data.Path, returns this:
/document/content://com.microsoft.skydrive.content.metadata/Drive/RID/phil%40mydomain.com/Item/RID/DC9388F99D04BA56%21369828/Property/?RefreshOption=AutoRefresh&RefreshTimeOut=15000&CostAttributionKey=11-21-1
which has nothing resembling the file name in it. I have found older stack posts on this, but they don't work for me. I have a feeling that the issue is with Android security and/or permissions that I need to give the app.
How do I grab the file name so I can display it in the UI?
Thanks #CommonsWare, you pointed me in the right direction. With the help of intellisense I noticed that the .Data property of the returned Intent was a Uri. So this is what (C# Xamarin) ended up working.
public override void OnActivityResult(int requestCode, int resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == -1 && requestCode == 42)
{
Intent ReturnedIntent = data;
// the code is in a Fragment here so we use Activity for the Context
DocumentFile df = DocumentFile.fromSingleUri(Activity, ReturnedIntent.Data);
string FileName = df.Name; // that contains the filename
I never would have got this on my own. I love that Android Java and Xamarin C# are so close. Thanks again #CommonsWare.
I have heard that the easiest way to implement ZXing barcode scanner into your own app is with an intent. However, nobody has explained how to do this in Android Studio. There's explanations for how to do it in Eclipse and Maven, but not Android Studio. Do I need to download anything other than the ZXing barcode scanner app, to implement it via intent? I think intents just call another app, but I'm not completely sure. Do I need to download a dependency (such as an AAR, JAR, or JAVA file) to get the ZXing intent to be accessible to an app? Please let me know how to use INTENTS with ANDROID STUDIO, in such a manner as to make it possible for the app I'm writing to use ZXing as its barcode scanner.
You can use ZXing in you app via gradle dependency . Add the following dependencies to your gradle file
compile 'com.journeyapps:zxing-android-embedded:3.1.0#aar'
compile 'com.google.zxing:core:3.2.0'
Then on your activity's onCreate method , add the following
IntentIntegrator scanIntegrator = new IntentIntegrator(MainActivity.this);
scanIntegrator.setPrompt("Scan a barcode");
scanIntegrator.setBeepEnabled(true);
scanIntegrator.setOrientationLocked(true);
scanIntegrator.setBarcodeImageEnabled(true);
scanIntegrator.initiateScan();
This will start a the scanner when you launch the Activity .
You can get the scan result , in onActivityResult
#Override
protected void onActivityResult(final int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
/*As an example in order to get the content of what is scanned you can do the following*/
String scanContent = scanningResult.getContents().toString();
}
You can Develop your own Bar-Code Scanner App: Try this references,
This is ZXing Jar Download Link: http://www.java2s.com/Code/Jar/z/Downloadzxingjar.htm
This is ZXing used to implement Barcode Scanner Reference Link: http://khurram2java.blogspot.in/
I am developing on a Android 4.0.3 device. How do I open a file browser for my app? Is there one built in the to Android SDK? Do I have to write my own?
I don't want my app to depend on a the user installing a separate app for file browsing.
To get a file from a file browser, use this:
Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT);
fileintent.setType("gagt/sdf");
try {
startActivityForResult(fileintent, PICKFILE_RESULT_CODE);
} catch (ActivityNotFoundException e) {
Log.e("tag", "No activity can handle picking a file. Showing alternatives.");
}
I'm not quite sure what the gagt/sdf is for... it seems to work in my app for any file.
Then add this method:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Fix no activity available
if (data == null)
return;
switch (requestCode) {
case PICKFILE_RESULT_CODE:
if (resultCode == RESULT_OK) {
String FilePath = data.getData().getPath();
//FilePath is your file as a string
}
}
If the user doesn't have a file manager app installed or preinstalled by their OEM you're going to have to implement your own. You might as well give them a choice.
I hope this one will help you for file picking:
public void performFileSearch() {
// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
// browser.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// Filter to only show results that can be "opened", such as a
// file (as opposed to a list of contacts or timezones)
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Filter to show only images, using the image MIME data type.
// If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
// To search for all documents available via installed storage providers,
// it would be "*/*".
intent.setType("image/*");
startActivityForResult(intent, READ_REQUEST_CODE);
}
The code is from this documentation:
https://developer.android.com/guide/topics/providers/document-provider.html
Refer to it for more information.
If someone would still need it for newer versions, it got updated with developing Storage Access Framework by Google for SDK >= 4.4. Check this Google site for further details:
https://developer.android.com/guide/topics/providers/document-provider.html
There is no single file-management app that is installed across all devices.
You probably want your app to be also working on devices with Android 3.x or lower.
The best choice you have though is writing your own file-manager. It isn't as much effort as it might sound, there is a lot of code on this already out there on the web.
I need my app to read text via Camera. I know there's the Tesseract library which does this, but I'd really prefer if there was an app that can handle Intents to read text via Camera, like Xzing does for reading QR codes.
Is there such an app?
There isn't currently an app on Google Play that does this.
I've thought about making one, but the possible use cases for such an app vary much more than for, say, scanning a QR code. There are different possible scenarios:
License plate recognition
Recognition for LCD 7-segment displays
Korean OCR
OCR for stylized text
OCR with shadows or uneven illumination
The different scenarios present a challenge for how to handle the image. A request to such an app via Intent would probably need to specify at least the type of thresholding to use for pre-processing the image along with the language/traineddata file to use.
I've just created an app that takes a photo using the Camera, crop the photo, and return the recognized text as result.
In your app, you may use the following code:
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo("sunbulmh.ocr", PackageManager.GET_ACTIVITIES);
Intent LaunchIntent = pm.getLaunchIntentForPackage("sunbulmh.ocr");
LaunchIntent.setFlags(0);
startActivityForResult(LaunchIntent,5);
} catch (NameNotFoundException e) {
Uri URLURI = Uri.parse("http://play.google.com/store/apps/details?id=sunbulmh.ocr");
Intent intent = new Intent(Intent.ACTION_VIEW,URLURI);
startActivity(intent);
}
Then, get the result in onActivityResult():
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if(requestCode == 5){
String ocr_txt = data.getStringExtra(Intent.EXTRA_TEXT);
// ocr_txt contains the recognized text.
}
}
}
I have downloaded the zxing 1.6 and was able to successfully run a standalone barcode scanner through it. Now this scanner is in another project and (the CaptureActivity) and I have my app's different project called MyProj , all I
want to do is on click of button in my project call CaptureActivity in another project , how do I import that entire project in my project or what do I do it get this working.
Thanking in advance
I think that "copying" Barcode Scanner and include it in your app might be overloading your projects. You should certainly use the Intent from the Scanner:
From here: http://code.google.com/p/zxing/wiki/ScanningViaIntent
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 like this:
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
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);
}
};
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
}
}
}
For more options, like scanning a product barcode, or asking Barcode Scanner to encode and display a barcode for you, see this source file:
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java
And here's some source from our test app which shows how to use them:
http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java
IntentIntegrator
We have also begun creating a small library of classes that encapsulate some of the details above. See IntentIntegrator for a possibly easier way to integrate. In particular this will handle the case where Barcode Scanner is not yet installed.
http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java
Via URL
As of Barcode Scanner v2.6, you can also launch the app from a URL in the Browser. Simple create a hyperlink to http://zxing.appspot.com/scan and Barcode Scanner will offer to launch to handle it. Users can also choose to always have Barcode Scanner open automatically.
NOTE: This URL is not meant to serve an actual web page in a browser, it's just a hook to launch a native app.
Known Issues
User jamesikanos reports the following 'gotcha':
Create a TabHost activity with launchMode "singleInstance"
Create a child activity with a "Start scan" button (launch zxing using the IntentIntegrator from this button)
onActivityResult in your child activity will return immediately as "cancelled"
onActivityResult is never called subsequently