Skip to content
Branch: master
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
doc
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

SmartID Scan Demo Android

SmartID Scan is a real-time video stream decoder, allowing to scan various type of content.

Depending on the version you downloaded, you'll be able to use it to decode any combination of the following codes :

  • 1D/2D barcodes (EAN8, EAN13, UPC, Code39, Code128, Datamatrix, databars, QRCodes, Aztec codes, ... )
  • Multiple OCR types :
    • OCR-B MRZ used on official papers (Swiss ID Cards, Swiss Passports, Swiss Driving license)
    • Swiss, German, French and Italian car plates
    • European Health Insurance Card
    • Swiss Inpayment Slips
  • Our decoder never stops growing, ask us about what's new in SmartID Scan !

Requirements

This project is a demo Android app to show how to integrate our decoding library in an Android Project. To make it work, just follow the few steps below.

  • Import this demo project into Android Studio
  • Download the decoding library from http://scan.smartidlab.com
  • Put the decoding library files you received under app/src/main/jnLibs in your project
app/src/main/jniLibs
app/src/main/jniLibs/arm64-v8a/libicaredecoders.so
app/src/main/jniLibs/armeabi-v7a/libicaredecoders.so
app/src/main/jniLibs/x86/libicaredecorders.so
app/src/main/jniLibs/x86-64/libicaredecorders.so
  • Then put smartscan-release.arr into the folder /smartscan-lib
  • Set the decoding type according to the decoding library you downloaded, into the MainActivityFragment (see below in Implementation) :

mSmartScanner.setDecodingType(IcareDecoders.CODE_OCRB, IcareDecoders.CODE_BVR);

Be careful because from the new version of Smart ID Scan you must enter a type and a subtype to start using the scanner.

Voilà! This is all you need to launch this project on a real device for testing purposes.

Don't forget to give camera permission to the app if you're using it on a device with API 23 or higher. This is not managed in this example code. See https://developer.android.com/training/permissions/requesting.html for help on this topic.

Implementation

SmartScanner

Interaction with the SmartID Scan library is done with a SmartScanner object. Instantiate it inside onCreate() method in your Activity and pass it a reference to your context.

mSmartScanner = new SmartScanner(getContext());

With the new version of SmartID Scan library you have a second constructor available.

mSmartScanner = SmartScanner(getContext(), cameraId, minScoreCameraAPI2);

cameraId : Set the camera id of your device. If you want that the library choose the best camera put NO_CAMERA_ID as value. minScoreCameraAPI2 : the minimal support for use the new camera api2 in SmartID Scan library. The options are : LEVEL_LIMITED, LEVEL_FULL, LEVEL_3, DEFAULT_MINIMAL_SCORE. DEFAULT_MINIMAL_SCORE is by default set to LEVEL_LIMITED

For more information about levels support on android

Now set the decoding type according to the decoding library you downloaded, using setDecodingType() method call on the SmartScanner object. This method allows use of bitwise operators if you have multiple decoding options :

 mSmartScanner.setDecodingType(CODE_OCRB | CODE_1D2D , CODE_BVR | CODE_QRC);

When using multiple decoders you will need probably to set manually the size of the region on interest (ROI) to have better results.

As SmartScanner involves calls to the Android Camera API, it is tightly coupled with the Activity lifecycle.

  • Call init() method of SmartScanner object in onResume() :
@Override
public void onResume() {
	//Checks if the application as the rights permission to run the camera
    if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED{
        //To improve with your own permision dialog, this is only as example
        Toast toast = Toast.makeText(getContext(), R.string.request_permission, Toast.LENGTH_SHORT);
        toast.show();
    }
    else {
        //Initialize the SmartScanner library
        mSmartScanner.init();
    }
}
  • To ensure resources are released when not needed anymore, call release() on SmartScanner object in onPause().
@Override
public void onPause() {
    mSmartScanner.release();
    super.onPause();
}

Layout and Views

Define a layout, with one CanvasDrawer for target display and one SurfaceView for camera preview, laying on top of each other :

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:id="@+id/activity_main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

	<!-- Displays the camera preview -->
    <ch.icare.smartscan.views.AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <!-- Displays targeting help. You can set target window color and width here using custom attributes -->
    <ch.icare.smartscan.CanvasDrawer
        android:id="@+id/canvasdrawer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/colorPrimaryDark"
        custom:targetWidth="4dp"
        custom:targetColor="@color/colorAccent"/>
     
    <!-- Displays the focus area -->   
    <View
        android:id="@+id/focus"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:visibility="gone"
        android:background="@drawable/rectangle" />

</FrameLayout>

Pass those two views to SmartScanner inside Activity or Fragment. Ensure you are fullscreen to prevent distorted preview from camera :

mSmartScanner.setCanvasDrawer((CanvasDrawer) root.findViewById(R.id.canvasdrawer));
mSmartScanner.setTextureView((AutoFitTextureView) root.findViewById(R.id.texture));

Permissions

Set needed features in app manifest :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.smartscan.myapplication">
    
    <uses-permission android:name="android.permission.FLASHLIGHT" ">
    <uses-permission android:name="android.permission.CAMERA" ">
    <uses-permission android:name="android.permission.VIBRATE" ">

    <uses-feature android:name="android.hardware.camera2.full" ">
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" ">
    <uses-feature
        android:name="android.hardware.camera.flash"
        android:required="false" ">
    
    ...


</manifest>

Depending on your targeted API level (23 and +), you should also manage app permission for the camera into your code.

Best practices

Some fonctionalities can only be activated when the library is fully loaded. To ensure that use the listener OnDecoderLoadedListener:

mSmartScanner.setOnLoadedListener(new OnDecoderLoadedListener() {
	  @Override
    public void onDecoderLoaded(Rect roi) {
        //Put your code here
    }
});

AndroidX - Android Extension Library

From last version of Smart ID Scan we starting using AndroidX for all of us projects. The migration of your existing projct to AndroidX is done very easily. Simply follow the steps describeds in the link:

https://developer.android.com/jetpack/androidx/migrate

You can find more information about AndroidX in the link below:

https://developer.android.com/jetpack/androidx

Android support

SmartID Scan is designed to work from Android 2.2 onwards. If your project supports lower versions of the Android framework, SmartID Scan may not work as expected and could show unexpected behaviour in your application.

Note that some low cost or old devices with poor camera hardware may have sub-optimal decoding capabilities.

Links

(1) The demonstration decoding libraries obfuscate some characters in the returned result string.

Institut Icare, SmartIdLab, 2019-05-28

About

No description, website, or topics provided.

Resources

License

Releases

No releases published

Languages

You can’t perform that action at this time.