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/
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 to develop an android application in which user speaks something and the wav file os send to the server where the googlespeech api shall return some text and i will display it on the android activity screen.
Note : Dont confuse urself with the android Text To Speech library i have to send the wav file
to the client's server.
Problem : I have no idea of howsoever to use this API. I can record the voice from the client and save it in a wav file but don't know how to proceed.
Refer Link : http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
You actually can't record a wav file and use it. At this moment the only way to do it is to get voice from the microphone using android intent:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-EN");
startActivityForResult(intent, CODE);
And then you can recievie the result in onActvityResult function:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
List<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
}
That is the basic idea.
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.
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
I am trying to use this 3rd Party Signature Capture Android Application with my PhoneGap Application. I have no idea how to "Call the right Activity" from my PhoneGap App. My Application is written in html and javascript.
Please help!
I have installed the application on my Droid X and it Captures my Signature with my finger. Its super smooth and quick.
http://www.binarysolutions.biz/
Here are the instructions from their website. They are not very detailed.
String key = ""; // set the key, any string you find suitable
String fileName = ""; // set the file name (global write permissions)
Intent intent = new Intent("biz.binarysolutions.signature.CAPTURE");
intent.putExtra(key, fileName);
intent.setComponent(
new ComponentName(
"biz.binarysolutions.signature",
"biz.binarysolutions.signature.Capture"
)
);
startActivityForResult(intent, CAPTURE_REQUEST_CODE);
Receiving the result
#Override
protected void onActivityResult
(
int requestCode,
int resultCode,
Intent data
) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAPTURE_REQUEST_CODE &&
resultCode == RESULT_OK) {
String fileName = ""; // the same file name as above
Bitmap bitmap = BitmapFactory.decodeFile(fileName);
// do with bitmap whatever you like
}
}
The integration of the signature application is doable via an Android Intent to invoke the signature app. Looks like you have the instructions for what you need to do on the Java (native) side to integrate with the signature application, but you are at a loss to do so inside a PhoneGap Android app.
Take a look at WebIntent. It is a PhoneGap Android plug-in - this is an extension to the PhoneGap API and is composed of a small JavaScript interface which your PhoneGap app uses, and a native (Java) component that the JS interface talks to. The WebIntent blog post linked above actually does a pretty good job of explaining a PhoneGap plug-in, too.
What you'll have to do on top of integrating the WebIntent plug-in is interfacing the WebIntent with the Signature app - so the intents getting passed around on the native side contain the proper parameters.
Starting from version 2.5 Signature Capture library can be started from the web browser just by clicking on a specific link. It can also 'upload' captured image to given url. Check out the instructions here:
http://www.binarysolutions.biz/2010/12/signature-capture-for-android.html#usage_web
Hope that could help.