How to get information by bar code? - android

I'm a new android developer, and I try to create an app for using bar code. I try ZXing, it is very easy. But now I need get information about product by bar code. How can I do that?

You'll need to use some kind of web service to look up the product information associated with an UPC/EAN code using for example an AsyncTask. A quick Google search turned up the Internet UPC Database.
Here's a sample record of what data they provide: http://www.upcdatabase.com/item/0081697521221
Please carefully read their ToS: http://www.upcdatabase.com/docs/terms.asp

To use one dimensional barcodes use PRODUCT_MODE.
If you want to be able to scan them all don't set anything in extras scan_mode.
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
//intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);

Bar code gives you nothing but a number (product number). You need to have a web service where you can send this number to get more details.

you have to call the barcode reader by intent, then the user scans the barcode(if they have the barcode reader installed), and the barcode reader sends the data to your app
here's the code on how to do it.
http://code.google.com/p/zxing/wiki/ScanningViaIntent
as you can see in public void onActivityResult
these are the data returned by the scanner
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

Related

How to share different texts based on package name in Android 10?

My app shares a specific URL to open in other apps, but I want to use a custom URL depending on what app the user is sharing it with. For example, with Gmail I want to use myurl.com?src=gmail, and with FB I want to use myurl.com?src=fb etc.
This normally would have worked with this famous method: https://stackoverflow.com/a/18068122/3015986.
However, in Android 10, that solution no longer works anymore: https://medium.com/#AndroidDeveloperLB/this-wont-work-anymore-on-android-q-1702c19eb7bb
So, what other options are there?
Well there are always options. In this particular case(with the given conditions regarding URL query parameter) I would suggest to create separate sharing method for each platform you want to share your content with rather than use the Android default sharing method.
For example here is a custom sharing for Facebook, etc. The method is quite time consuming though.
But there is a better option to handle such cases. It is a relatively new method to get info about which app was chosen. It is easy. Basically you will need to:
Create a PendingIntent for a BroadcastReceiver and supply its IntentSender in Intent.createChooser() like this:
Intent share = new Intent(ACTION_SEND);
...
PendingIntent pi = PendingIntent.getBroadcast(myContext, requestCode,
new Intent(myContext, MyBroadcastReceiver.class),
FLAG_UPDATE_CURRENT);
share = Intent.createChooser(share, null, pi.getIntentSender());
Receive the callback in MyBroadcastReceiver and look in Intent.EXTRA_CHOSEN_COMPONENT like this:
#Override public void onReceive(Context context, Intent intent) {
...
ComponentName clickedComponent = intent.getParcelableExtra(EXTRA_CHOSEN_COMPONENT);
}
More info here
Though you cannot change your URL for each specific case because the sharing event has already occurred, you can implement separate API call or URL link using which you can gather analytics data, change the outcome of the URL click you sent(if you control the backend, of course) or just show a customized message to the user of your app.
Keep in mind, that for some usecases of this method, URL you share should be unique per user(for ex. to change the outcome of the URL click etc).
Hope it helps.

Android Document Picker like whatsapp

I have been able to open audio file picker like whatsapp using following code.
Intent intent = new Intent(Intent.ACTION_PICK,
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
return intent;
However, I want to open the file picker in the same as it is shown in whatsapp. I am using the following code and other similar codes. However, I am not able to show document picker exact like whatsapp. The following code opens the document picker and it shows explorer and take me to Recent folder as starting point.
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// The MIME data type filter
intent.setType("application/*");
// Only return URIs that can be opened with ContentResolver
intent.addCategory(Intent.CATEGORY_OPENABLE);
It shows differently on different devices as well. I want to make it consistent.
Apologies for giving answer late. I don't know this is exact answer you are looking for. But i implemented image and document picker with below code.
https://github.com/DroidNinja/Android-FilePicker

Scan QR code and display it along with its value

I am using Zxing Barcode scanner app to scan bar codes using
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
I could get the result in onActivityResult.I want to display the value of QR code and the QR code itself.
I am unable to figure out how can I scan and capture the image of the QR code at the same time.
Any way to achieve that?
ZXing doesn't actually take a picture when doing scanning. It does "capture" the image off the camera feed, but it doesn't persist anything to the SSD card or memory. You can get at the raw bytes if you're scanning with the IntentIntegrator code they post on their site.
http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentResult.java
You can see the IntentResult has the raw bytes. I don't exactly know what format it is in, but I bet you can pass it to Bitmap to get the image.

QR Code scanning android

I am using Zxing Barcode scanner app to scan bar codes using
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
It works fine. I could get the result in onActivityResult. No problem. I dont want QRCode to be displayed. I mean I don't want to let the end user know the qr code string. But in the history available in the original barcode scanner app, it is showing up the list of QR's scanned. So, how do i make the QRStringfrom my app invisible in History
"SAVE_HISTORY" from package com.google.zxing.client.android.Scan;
/**
* Setting this to false will not save scanned codes in the history.
*/
public static final String SAVE_HISTORY = "SAVE_HISTORY";
Then something like,
intent.putExtra("SAVE_HISTORY", false);
Try this and let me know what happen..

ZXing doesn't read 1D barcode in Android app

I am developing a new application which hopefully will use a barcode reader to scan and find books. I will then use the ISBN information to get more information.
The intents work and I can scan 2d barcodes ok but not the 1d barcodes of books which I know scan fine using the full application.
This is my code. I have tried it without putting the intent extras and it doesn't change anything.
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent, 0);
Is there something obvious I am missing? The settings in the app also are selected on 1d scanning only.
Thanks
Turns out that using product mode worked perfectly. I don't know why I didn't try that earlier!
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
(Probably easiest if I answer in just one place: http://code.google.com/p/zxing/issues/detail?id=574 )

Categories

Resources