This guide provides an overview of how to build and run the sample app using our Android SDK.

Prerequisites

These are the frameworks you must have before building the app:

  • Visual Studio Community 8.1 or later
  • Minimum Android SDK version: 8
  • The latest SDK files (version 3.6.1503.2022) and Code Sample App from your Account Manager.

Step 1: Prepare your development environment

  • Open the Visual Studio Community.
  • Open folder
  • Select the Your App > MainActivity.cs.

Step 2: Import the SDK

  • Download the SDK files that contain all the .dll files from your account manager, then copy them.
590590
  • Import the following code to the MainActivity.cs
using Com.Ocrlabs.Orbit.Mrz;
using Com.Ocrlabs.Orbitmedicare;
using CCMedicare = Com.Ocrlabs.Orbitmedicare.CContext;
using Com.Ocrlabs.Orbitsdk;
using CCDriverLicense = Com.Ocrlabs.Orbitsdk.CContext;
using System.Collections.Generic;
600600
  • Save the file.

Step 3: Create the Button

For example, you want to create an app to scan your driving license, passport, and Medicare card.

  • On the Explorer bar of the Visual Studio Community, go to Your App > Resources > layout > activity_main.axml
  • Inside the LinearLayout, create the new button with the following code:
<Button
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="4dp"
        android:id="@+id/btnDriverLicense"
        android:text="@string/driver_license"
        android:onClick="BtnDriverLicenseClicked"
        style="@style/FooterButton"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />

    <Button
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="4dp"
        android:id="@+id/btnPassport"
        android:text="@string/passport"
        android:onClick="BtnPassportClicked"
        style="@style/FooterButton"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />

    <Button
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="24dp"
        android:id="@+id/btnMedicare"
        android:text="@string/medicare"
        android:onClick="BtnMedicareClicked"
        style="@style/FooterButton"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />
800800
  • Enable the screen scroll by adding the following code inside the LinearLayout.
<ScrollView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
        android:layout_weight="1">
        <TextView
        android:id="@+id/tvResult"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:textAlignment="center"/>
    </ScrollView>

Step 4: Add the Text for Each SDK

  • Create the text OrbitSDK, OrbitMRZ, and OrbitMedicare inside the LinearLayout.
  • Insert the following code:
<TextView
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:text="OrbitMRZ"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/version_MRZ" />

    <TextView
        android:layout_marginLeft="8dp"
        android:text="OrbitMedicare"
        android:layout_width="match_parent"
        android:id="@+id/version_Medicare"
        android:layout_height="wrap_content"/>

    <TextView
        android:layout_marginLeft="8dp"
        android:layout_marginBottom="8dp"
        android:text="OrbitSdk"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/version_Dl" />
  • Go to the development environment (MainActivity.cs).
  • In the Your App space, import the following code from the activity_main to set the content view:
FindViewById(Resource.Id.btnDriverLicense).Click += BtnDriverLicenseClicked;
FindViewById(Resource.Id.btnPassport).Click += BtnPassportClicked;
FindViewById(Resource.Id.btnMedicare).Click += BtnMedicareClicked;
800800
  • Add the click function for every SDK. Please refer to the code below.
private void BtnDriverLicenseClicked(object sender, System.EventArgs e)
        {
            GC.Collect();
            mType = OrbitType.DriverLicense;
            LaunchOrbitSDK("AUS_AUTO_DRIVERLICENCE");
        }

        private void BtnPassportClicked(object sender, System.EventArgs e)
        {
            GC.Collect();
            LaunchPassportSDK();
        }

        private void BtnMedicareClicked(object sender, System.EventArgs e)
        {
            GC.Collect();
            LaunchMedicareSDK();
        }
800800

Step 5: Initialize the SDKs

To start the scanning process, please refer to the following steps.

  • Initialize the OrbitSDK by inserting the code below on the MainActivity.cs
OrbitSDK anz = new OrbitSDK(this);
800800

OrbitSDK initialization

  • Initialize the OrbitMrzSDK by inserting the code below on the MainActivity.cs
OrbitMrzSDK mrz = new OrbitMrzSDK(this)
800800

OrbitMrzSDK initialization.

  • Initialize the Medicare SDK by inserting the code below on the MainActivity.cs
OrbitMedicareSDK medicareSdk = new OrbitMedicareSDK(this);
800800

OrbitMedicareSDK initialization.

Step 6: Set the SDK variables

To customize the app display, add the variables. Please refer to the codes below. You can add the variables below the initialization code.

800800
  • Setting the OrbitSDK variables:
CCDriverLicense.OverlayHeaderLabelText = "";
CCDriverLicense.OverlayHeaderLabelColor = Color.White;
CCDriverLicense.OverlayHeaderLabelTextSize = 20;
CCDriverLicense.OverlaySubLabelText = "";
CCDriverLicense.OverlaySubLabelColor = Color.White;
CCDriverLicense.OverlaySubLabelTextSize = 12;

CCDriverLicense.CloseButton.ButtonVisible = true;
CCDriverLicense.SettingButton.ButtonVisible = false;
CCDriverLicense.ManualEntryButton.ButtonVisible = false;
CCDriverLicense.CameraSwitchButton.ButtonVisible = false;
CCDriverLicense.RecaptureButton.ButtonVisible = false;
  • Setting the OrbitMrzSDK variables:
mrz.ScanMode = OrbitSDK.ScanmodeCamera;
mrz.OverlayHeaderLabelText = "";
mrz.OverlaySubLabelText = "";
mrz.CloseButton.ButtonVisible = true;
mrz.HideBrandMark = true;
mrz.FlashButton.ButtonVisible = false;
  • Setting the Medicare SDK variables:
CCMedicare.OverlayHeaderLabelText = "";
CCMedicare.OverlaySubLabelText = "";
CCMedicare.CloseButton.ButtonVisible = true;
CCMedicare.ManualEntryButton.ButtonVisible = false;
CCMedicare.CameraSwitchButton.ButtonVisible = false;

Step 7: Enable the camera scanner with the Start Function

After adding the variables, use the Start function to start the scanning process.

800800
  • Start function for Driver License button by inserting the code below under the MainActivity.cs
anz.Start("AUS_AUTO_DRIVERLICENCE", OrbitSDK.RequestCodeScan);
  • Start function for Passport button by inserting the code below under the MainActivity.cs
mrz.start(OrbitMrzSDK.ScanRequestCode);
  • Start function for Medicare button by inserting the code below under the MainActivity.cs
medicare.Start(OrbitMedicareSDK.RequestCodeScan);

Step 8: Add the build date and version function

To add the build date and version for each SDK, follow these steps:

  • Insert the code of the function below under the MainActivity.cs:
public void showSdkBuiltDate()
{
 String buildDateMrz = OrbitMrzSDK.SdkBuildDate();
 TextView mrzSdkDate = (TextView)FindViewById(Resource.Id.version_MRZ);
 mrzSdkDate.Text = "OrbitMRZ" + " " + buildDateMrz;

 String buildDateMed = OrbitMedicareSDK.SdkBuildDate();
 TextView medicareSdkDate = (TextView)FindViewById(Resource.Id.version_Medicare);
 medicareSdkDate.Text = "OrbitMed" + " " + buildDateMed;

 String buildDateDl = OrbitSDK.SdkBuildDate();
 TextView dlSdkDate = (TextView)FindViewById(Resource.Id.version_Dl);
 dlSdkDate.Text = "OrbitSdk" + " " + buildDateDl;
}
  • Insert this code to show the version and the build date on the app display:
((Textview)FindViewById(Resource.Id.version_01)).Text = "OrbitSdk Build Date: "
+ buildDateSdk + "Version: " + versionSdk;
((Textview)FindViewById(Resource.Id.version_MRZ)).Text = "OrbitMrz Build Date: "
+ buildDateMrz + "Version: " + versionMrz;
((Textview)FindViewById(Resource.Id.version_Medicare)).Text = "OrbitMed Build Date: "
+ buildDateMedicare + "Version: " + versionMedicare;
800800

Step 9: Add the onActivityResult function

To retrieve the result from the scanning activity, use the onActivityResult function as follow.

  • Insert the function below under the MainActivity.cs:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (resultCode == Result.Ok || (int)resultCode == OrbitSDK.ResponseOk)
            {
                string resultString = "";

                switch (mType)
                {
                    case OrbitType.DriverLicense:
                        ScanIDOCRResult driverResult = (ScanIDOCRResult)data.GetParcelableExtra("RESULT");
                        resultString = JsonConvert.SerializeObject(JObject.Parse(driverResult.ResultString)["CardInfo"]);
                        resultString = resultString != "null" ? resultString : driverResult.ResultString;
                        break;
                    case OrbitType.Passport:
                        resultString = ((MRZOCRResult)data.GetParcelableExtra("RESULT")).ResultString;
                        break;
                    case OrbitType.Medicare:
                        MedicareOCRResult medicareResult = (MedicareOCRResult)data.GetParcelableExtra("RESULT");
                        resultString = JsonConvert.SerializeObject(JObject.Parse(medicareResult.ResultString)["CardInfo"]);
                        resultString = resultString != "null" ? resultString : medicareResult.ResultString;
                        break;
                }

                try
                {
                    var licenceObject = JsonConvert.DeserializeObject<OCRResponseModel>(resultString);
                    if (licenceObject != null && (licenceObject.StatusCode == "210" || licenceObject.StatusCode == "230" || licenceObject.StatusCode == "240"))
                    {
                        var alert = new Android.App.AlertDialog.Builder(this);
                        alert.SetTitle("Failed!");
                        alert.SetMessage("Error occurred while getting result. Status code is " + licenceObject.StatusCode + ", " + licenceObject.StatusMessage);
                        alert.Show();
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    tvResult.Text = resultString;
                }
            }
            else if ((int)resultCode == OrbitSDK.ResponseErrorCameraAccess)
            {
                var alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Access camera");
                alert.SetMessage("Can not open camera!");
                alert.Show();
            }
            else if ((int)resultCode == OrbitSDK.ResponseErrorCameraResolution)
            {
                var alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Access camera");
                alert.SetMessage("Camera resolution is too low!");
                alert.Show();
            }
            else if (resultCode == Result.Canceled)
            {
                var alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Warning");
                alert.SetMessage("User cancelled the operation.");
                alert.Show();
            }
            else
            {
                var alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Request Code: " + requestCode);
                alert.SetMessage("Result Code: " + resultCode);
                alert.Show();
            }
        }
800800

Step 10: Try the App

Once you completed the prerequisites and steps above, you will have the app ready. The app display will look like this.

624624

You can simulate the buttons for each document.

💬 We're here to help!

If you encounter an issue, a bug, or require assistance, please contact our support page here to find the solution. Don't forget to provide any important information on the issue.