Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate Zxing without installing barcode scanner application?

Tags:

android

I added Zying android application to my application as library. Then edited Manifest.xml and tried to use Intent integrator. No luck.

Downloading scanner app is totally unreasonable.

By the way:

Intent scanIntent = new Intent("com.google.zxing.client.android.SCAN");
scanIntent.setPackage("com.google.zxing.client.android");

11-11 15:15:27.793: WARN/System.err(15384): android.content.ActivityNotFoundException: No 
Activity found to handle Intent { act=com.google.zxing.client.android.SCAN 
cat=[android.intent.category.DEFAULT] pkg=com.google.zxing.client.android (has extras) }
like image 766
Onuray Sahin Avatar asked Nov 11 '11 14:11

Onuray Sahin


People also ask

How do I scan a barcode without an app?

With Google Screen Search, Android 8 users can scan QR codes without the need for an app. Simply point your camera at the QR code, press and hold the “Home” button, then select 'What's on my screen? ' Users can then open the brief URL associated with the QR Code's information.

Can you just scan a QR code without an app?

Yes. Just like iPhones, Android 9 (Android Pie) and Android 10 have an in-built QR Code reader. Even the Android 8 or Oreo does not need an app to scan QR Codes.

Can you scan without barcode?

Mobile workers can now automatically capture the data behind human- readable characters without barcodes or RFID. Using imaging software with a mobile computer, your field and mobile workers can capture an image of human- readable characters as easily as scanning a barcode or taking a picture.

How do I use Google ZXing?

In order to use the Zxing library in our application we need to add it's dependency in our application's gradle file. For adding the dependency Go to Gradle Scripts > build. gradle(Module: app) and add the following dependencies. After adding the dependency you need to click on Sync Now.


1 Answers

You are trying to access the ZXing scanner in two directly conflicting ways. The purpose of the IntentIntegrator that ZXing provides is to make accessing the external scanner app simpler by building the Intent for you with all the appropriate constants and flags. If you do not want to install and run the external scanner app from Android Market on a device, IntentIntegrator is not for you. This is also true wit the Java code you posted, as it is essentially the same Intent the integrator would create to launch the external application.

If you integrate ZXing into your project as a library, then the components become a part of your application and they must be referenced as such. For example, a declaration in AndroidManifest.xml needs to be added such as:

<activity android:name="com.google.zxing.client.android.CaptureActivity"
  android:screenOrientation="landscape"
  android:configChanges="orientation|keyboardHidden"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
  android:windowSoftInputMode="stateAlwaysHidden">
  <intent-filter>
    <action android:name="com.google.zxing.client.android.SCAN"/>
    <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
</activity> 

Make sure you used the correct name here for the activity and action, as these have to reference the library. Then you can launch the scanner Activity from your Java code using the following:

int REQUEST_SCAN; //Request code for Intent result
String packageString = "com.yourapplication.packagename";

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage(packageString);
//Add any optional extras to pass
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
//Launch
startActivityForResult(intent, REQUEST_SCAN);

Notice the Intent action matches the declaration in the manifest, but the PACKAGE is this application, not the Android Market ZXing application.

HTH

like image 144
devunwired Avatar answered Oct 20 '22 05:10

devunwired