Implementation
Aviso Importante!
Starting from version 5.0.0, the authentication system has been updated to use a dynamic token instead of mobileToken. Before configuring the SDK, you must generate a temporary token through a server-to-server request to our Device Scan API.
package com.example.zaig_device_scan_sdk_test_app;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.zaig.android.devicescan.DeviceScan;
import com.zaig.android.devicescan.DeviceScanNotifier;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private DeviceScan deviceScan;
private DeviceScanNotifier deviceScanNotifier;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
deviceScanNotifier = new DeviceScanNotifier(this);
}
public void sendDeviceScan(View view) {
try{
deviceScan = new DeviceScan.Builder(this.getApplicationContext())
.setToken(this.token)
.setSessionId(this.sessionId)
.setNotifier(this.deviceScanNotifier)
.setSandboxEnvironment()
.build();
}catch (Exception ex) {
Log.e("DeviceScan Error", "There was an error collecting DeviceScan data: " + ex.toString());
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
try{
deviceScan.collectData(this.documentNumber,
this.eventId,
this.eventType);
}catch (Exception ex) {
Log.e("DeviceScan Error", "There was an error collecting DeviceScan data: " + ex.toString());
}
}
private class ScanNotifier implements DeviceScanNotifier {
AppCompatActivity activity;
public ScanNotifier (AppCompatActivity myActivity){
// This method is customizable and can be used to store the Activity, which is used to operate the UI
this.activity = myActivity;
}
public void onSuccess(){
Log.i("DeviceScan", "DeviceScan successfully submitted");
runOnUiThread(new Runnable() {
@Override
public void run() {
// Add here any UI changes that are required after the device scan is sent successfully
}
});
}
public void onError(){
Log.i("DeviceScan", "DeviceScan submission failed");
runOnUiThread(new Runnable() {
@Override
public void run() {
// Add here any UI changes that are required after the device scan is sent successfully
}
});
}
}
}
To use the Android device scan SDK, the following steps are required:
- Add the required permissions to the application's manifest;
- Import the library into the application project;
- When starting the application, instantiate the library, passing the appropriate parameters in its constructor, including the Notifier, responsible for providing the operation callback with the result;
- Use the Activity’s
onRequestPermissionsResultfunction to be notified of whether the required permissions were approved or not; - Request permissions from the user. Internet access permission is mandatory for the library to work;
- Once you are notified of whether permissions were approved or not, collect and send the data using the
collectDatamethod.