If you want to use ZXing for barcode reading, but do not want your customer to install a third party app. Or if you just can’t because the Android device you are using cannot connect to the Play store (as is the case with many wearables), there is an extremely easy way to use the ZXing scanner in your app, using Android Studio. No need to download anything, install libraries, compile entire code trees:

To embed the library, add these two lines to your app.gradle:

dependencies {
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
}

Then, to initiate a scan, call this in your Activity:

new IntentIntegrator(this).initiateScan();

Finally, you use this code to receive the result:

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
      }
   }
}
Categorieën: GeekstuffSnack

0 reacties

Geef een reactie

Avatar plaatshouder

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.