Kaynağa Gözat

添加指纹采集测试页

Frankensteinly 8 ay önce
ebeveyn
işleme
ec77857566

BIN
app/libs/zkandroidcore.jar


BIN
app/libs/zkandroidfingerservice.jar


BIN
app/libs/zkandroidfpreader.jar


+ 3 - 0
app/src/main/AndroidManifest.xml

@@ -37,6 +37,9 @@
         <activity
             android:name=".view.activity.test.face.FaceActivity"
             android:exported="false" />
+        <activity
+            android:name=".view.activity.test.fingerprint.FingerPrintActivity"
+            android:exported="false" />
         <activity
             android:name=".view.activity.HomeActivity"
             android:exported="false" />

+ 6 - 1
app/src/main/java/com/grkj/iscs/view/activity/MainActivity.kt

@@ -1,7 +1,7 @@
 package com.grkj.iscs.view.activity
 
 import android.content.Intent
-import com.grkj.iscs.FaceActivity
+import com.grkj.iscs.view.activity.test.face.FaceActivity
 import com.grkj.iscs.view.base.BaseActivity
 import com.grkj.iscs.databinding.ActivityMainBinding
 import com.grkj.iscs.presentation.PresentationActivity
@@ -11,6 +11,7 @@ import com.grkj.iscs.view.activity.test.RfidActivity
 import com.grkj.iscs.view.activity.test.ModbusActivity
 import com.grkj.iscs.view.activity.test.WidgetTestActivity
 import com.grkj.iscs.view.activity.test.WebSocketActivity
+import com.grkj.iscs.view.activity.test.fingerprint.FingerPrintActivity
 
 class MainActivity : BaseActivity<ActivityMainBinding>() {
 
@@ -61,5 +62,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
         mBinding?.face?.setOnClickListener {
             startActivity(Intent(this, FaceActivity::class.java))
         }
+
+        mBinding?.finger?.setOnClickListener {
+            startActivity(Intent(this, FingerPrintActivity::class.java))
+        }
     }
 }

+ 146 - 0
app/src/main/java/com/grkj/iscs/view/activity/test/fingerprint/DBManager.java

@@ -0,0 +1,146 @@
+package com.grkj.iscs.view.activity.test.fingerprint;
+
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import java.util.HashMap;
+
+public class DBManager {
+    private String dbName;
+    SQLiteDatabase db = null;
+    boolean bIsOpened = false;
+    public boolean opendb(String fileName)
+    {
+        if (bIsOpened)
+        {
+            return true;
+        }
+        dbName = fileName;
+        db = SQLiteDatabase.openOrCreateDatabase(dbName, null);
+        if (null == db)
+        {
+            return false;
+        }
+        String strSQL = "create table if not exists userinfo(id integer primary key autoincrement,pin text not null,feature text not null)";
+        db.execSQL(strSQL);
+        bIsOpened = true;
+        return true;
+    }
+
+    public boolean isUserExited(String pin)
+    {
+        if (!bIsOpened)
+        {
+            opendb(dbName);
+        }
+        if (null == db)
+        {
+            return false;
+        }
+        Cursor cursor = db.query("userinfo", null, "pin=?", new String[] { pin }, null, null, null);
+        return cursor.getCount() > 0;
+    }
+
+    public boolean deleteUser(String pin)
+    {
+        if (!bIsOpened)
+        {
+            opendb(dbName);
+        }
+        if (null == db)
+        {
+            return false;
+        }
+        db.delete("userinfo", "pin=?", new String[] { pin });
+        return true;
+    }
+
+
+    public boolean clear()
+    {
+        if (!bIsOpened)
+        {
+            opendb(dbName);
+        }
+        if (null == db)
+        {
+            return false;
+        }
+        String strSQL = "delete from userinfo;";
+        db.execSQL(strSQL);
+        return true;
+    }
+
+    public boolean modifyUser(String pin, String feature)
+    {
+        if (!bIsOpened)
+        {
+            opendb(dbName);
+        }
+        if (null == db)
+        {
+            return false;
+        }
+        ContentValues value = new ContentValues();
+        value.put("feature", feature);
+        db.update("userinfo", value, "pin=?", new String[] { pin });
+        return true;
+    }
+
+    public int getCount()
+    {
+        if (!bIsOpened)
+        {
+            opendb(dbName);
+        }
+        if (null == db)
+        {
+            return 0;
+        }
+        Cursor cursor = db.query("userinfo", null, null, null, null, null, null);
+        return cursor.getCount();
+    }
+
+    public boolean insertUser(String pin, String feature)
+    {
+        if (!bIsOpened)
+        {
+            opendb(dbName);
+        }
+        if (null == db)
+        {
+            return false;
+        }
+        ContentValues value = new ContentValues();
+        value.put("pin", pin);
+        value.put("feature", feature);
+        db.insert("userinfo", null, value);
+        return true;
+    }
+
+    public HashMap<String, String> queryUserList()
+    {
+        if (!bIsOpened)
+        {
+            return null;
+        }
+        if (null == db)
+        {
+            return null;
+        }
+        Cursor cursor = db.query("userinfo", null, null, null, null, null, null);
+        if (cursor.getCount() == 0)
+        {
+            cursor.close();
+            return null;
+        }
+        HashMap<String, String> map = new HashMap<String, String>();
+        for (cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()) {
+           map.put(cursor.getString(cursor.getColumnIndex("pin")), cursor.getString(cursor.getColumnIndex("feature")));
+        }
+        cursor.close();
+        return map;
+    }
+
+}

+ 361 - 0
app/src/main/java/com/grkj/iscs/view/activity/test/fingerprint/FingerPrintActivity.kt

@@ -0,0 +1,361 @@
+package com.grkj.iscs.view.activity.test.fingerprint
+
+import android.Manifest
+import android.graphics.Bitmap
+import android.hardware.usb.UsbDevice
+import android.hardware.usb.UsbManager
+import android.util.Base64
+import android.util.Log
+import com.grkj.iscs.databinding.ActivityFingerPrintBinding
+import com.grkj.iscs.util.log.LogUtil
+import com.grkj.iscs.view.activity.test.fingerprint.ZKUSBManager.ZKUSBManager
+import com.grkj.iscs.view.activity.test.fingerprint.ZKUSBManager.ZKUSBManagerListener
+import com.grkj.iscs.view.base.BaseActivity
+import com.zkteco.android.biometric.FingerprintExceptionListener
+import com.zkteco.android.biometric.core.device.ParameterHelper
+import com.zkteco.android.biometric.core.device.TransportType
+import com.zkteco.android.biometric.core.utils.LogHelper
+import com.zkteco.android.biometric.core.utils.ToolUtils
+import com.zkteco.android.biometric.module.fingerprintreader.FingerprintCaptureListener
+import com.zkteco.android.biometric.module.fingerprintreader.FingerprintSensor
+import com.zkteco.android.biometric.module.fingerprintreader.FingprintFactory
+import com.zkteco.android.biometric.module.fingerprintreader.ZKFingerService
+import com.zkteco.android.biometric.module.fingerprintreader.exception.FingerprintException
+
+class FingerPrintActivity : BaseActivity<ActivityFingerPrintBinding>() {
+
+    companion object {
+        private const val REQUEST_PERMISSION_CODE = 9
+        private const val ZKTECO_VID: Int = 0x1b55
+        private const val LIVE20R_PID: Int = 0x0120
+        private const val LIVE10R_PID: Int = 0x0124
+        private const val ENROLL_COUNT: Int = 3
+    }
+
+    private var bStarted = false
+    private var usb_pid = 0
+    private var zkusbManager: ZKUSBManager? = null
+    private val usb_vid: Int = ZKTECO_VID
+    private var fingerprintSensor: FingerprintSensor? = null
+    private var bRegister = false
+    private var enroll_index = 0
+    private var isReseted = false
+    private val deviceIndex = 0
+    private val regtemparray = Array(3) {
+        ByteArray(
+            2048
+        )
+    }
+//    private val dbManager: DBManager = DBManager()
+    private val strUid: String? = null
+//    private var dbFileName: String? = null
+
+
+    override val viewBinding: ActivityFingerPrintBinding
+        get() = ActivityFingerPrintBinding.inflate(layoutInflater)
+
+    override fun initView() {
+//        dbFileName = filesDir.absolutePath + "/zkfinger10.db"
+        checkStoragePermission()
+        zkusbManager = ZKUSBManager(this.applicationContext, zkusbManagerListener)
+        zkusbManager?.registerUSBPermissionReceiver()
+        
+        mBinding?.start?.setOnClickListener {
+            if (bStarted) {
+                mBinding?.txtResult?.setText("Device already connected!")
+                return@setOnClickListener
+            }
+            if (!enumSensor()) {
+                mBinding?.txtResult?.setText("Device not found!")
+                return@setOnClickListener
+            }
+            tryGetUSBPermission()
+        }
+
+        mBinding?.stop?.setOnClickListener {
+
+        }
+        
+        mBinding?.register?.setOnClickListener {
+
+        }
+        
+        mBinding?.identify?.setOnClickListener {
+
+        }
+        
+        
+        mBinding?.delete?.setOnClickListener {
+
+        }
+        
+        mBinding?.clear?.setOnClickListener {
+
+        }
+
+        mBinding?.exit?.setOnClickListener {
+            finish()
+        }
+    }
+
+    private fun checkStoragePermission() {
+        val permission = arrayOf(
+            Manifest.permission.READ_EXTERNAL_STORAGE,
+            Manifest.permission.WRITE_EXTERNAL_STORAGE
+        )
+        val deniedPermissions: ArrayList<String> = PermissionUtils.checkPermissions(
+            this, permission
+        )
+        if (deniedPermissions.isEmpty()) {
+            //permission all granted
+            LogUtil.i("[checkStoragePermission]: all granted")
+        } else {
+            val size = deniedPermissions.size
+            val deniedPermissionArray = deniedPermissions.toTypedArray<String>()
+            PermissionUtils.requestPermission(this, deniedPermissionArray, REQUEST_PERMISSION_CODE)
+        }
+    }
+
+    private fun afterGetUsbPermission() {
+        openDevice()
+    }
+
+    private fun tryGetUSBPermission() {
+        zkusbManager?.initUSBPermission(usb_vid, usb_pid)
+    }
+
+
+    private val fingerprintCaptureListener: FingerprintCaptureListener =
+        object : FingerprintCaptureListener {
+            override fun captureOK(fpImage: ByteArray?) {
+                val bitmap: Bitmap = ToolUtils.renderCroppedGreyScaleBitmap(
+                    fpImage,
+                    fingerprintSensor?.getImageWidth()!!,
+                    fingerprintSensor?.getImageHeight()!!
+                )
+                runOnUiThread { mBinding?.imageFP?.setImageBitmap(bitmap) }
+            }
+
+            override fun captureError(e: FingerprintException?) {
+                // nothing to do
+            }
+
+            override fun extractOK(fpTemplate: ByteArray?) {
+                if (bRegister) {
+                    doRegister(fpTemplate)
+                } else {
+                    doIdentify(fpTemplate)
+                }
+            }
+
+            override fun extractError(i: Int) {
+                // nothing to do
+            }
+        }
+
+    private val fingerprintExceptionListener: FingerprintExceptionListener =
+        object : FingerprintExceptionListener {
+            override fun onDeviceException() {
+                LogUtil.e("usb exception!!!")
+                if (!isReseted) {
+                    try {
+                        fingerprintSensor?.openAndReboot(deviceIndex)
+                    } catch (e: FingerprintException) {
+                        e.printStackTrace()
+                    }
+                    isReseted = true
+                }
+            }
+        }
+
+    private val zkusbManagerListener: ZKUSBManagerListener = object : ZKUSBManagerListener {
+        override fun onCheckPermission(result: Int) {
+            afterGetUsbPermission()
+        }
+
+        override fun onUSBArrived(device: UsbDevice?) {
+            if (bStarted) {
+                closeDevice()
+                tryGetUSBPermission()
+            }
+        }
+
+        override fun onUSBRemoved(device: UsbDevice?) {
+            LogUtil.d("usb removed!")
+        }
+    }
+
+    private fun openDevice() {
+        createFingerprintSensor()
+        bRegister = false
+        enroll_index = 0
+        isReseted = false
+        try {
+            //fingerprintSensor?.setCaptureMode(1);
+            fingerprintSensor?.open(deviceIndex)
+            //load all templates form db
+//            if (dbManager.opendb(dbFileName) && dbManager.getCount() > 0) {
+//                val vUserList: HashMap<String, String> = dbManager.queryUserList()
+//                var ret = 0
+//                if (vUserList.size > 0) {
+//                    for ((strID, strFeature) in vUserList) {
+//                        val blobFeature = Base64.decode(strFeature, Base64.NO_WRAP)
+//                        ret = ZKFingerService.save(blobFeature, strID)
+//                        if (0 != ret) {
+//                            LogUtil.e("add [$strID] template failed, ret=$ret")
+//                        }
+//                    }
+//                }
+//            }
+            run {
+                // device parameter
+                LogUtil.d("sdk version" + fingerprintSensor?.getSDK_Version())
+                LogUtil.d("firmware version" + fingerprintSensor?.getFirmwareVersion())
+                LogUtil.d("serial:" + fingerprintSensor?.getStrSerialNumber())
+                LogUtil.d("width=" + fingerprintSensor?.getImageWidth() + ", height=" + fingerprintSensor?.getImageHeight())
+            }
+            fingerprintSensor?.setFingerprintCaptureListener(deviceIndex, fingerprintCaptureListener)
+            fingerprintSensor?.SetFingerprintExceptionListener(fingerprintExceptionListener)
+            fingerprintSensor?.startCapture(deviceIndex)
+            bStarted = true
+            mBinding?.txtResult?.setText("connect success!")
+        } catch (e: FingerprintException) {
+            e.printStackTrace()
+            // try to  reboot the sensor
+            try {
+                fingerprintSensor?.openAndReboot(deviceIndex)
+            } catch (ex: FingerprintException) {
+                ex.printStackTrace()
+            }
+            mBinding?.txtResult?.setText("connect failed!")
+        }
+    }
+
+    private fun closeDevice() {
+        if (bStarted) {
+            try {
+                fingerprintSensor?.stopCapture(deviceIndex)
+                fingerprintSensor?.close(deviceIndex)
+            } catch (e: FingerprintException) {
+                e.printStackTrace()
+            }
+            bStarted = false
+        }
+    }
+
+    private fun enumSensor(): Boolean {
+        val usbManager = this.getSystemService(USB_SERVICE) as UsbManager
+        for (device in usbManager.deviceList.values) {
+            val device_vid = device.vendorId
+            val device_pid = device.productId
+            if (device_vid == ZKTECO_VID && (device_pid == LIVE20R_PID || device_pid == LIVE10R_PID)) {
+                usb_pid = device_pid
+                return true
+            }
+        }
+        return false
+    }
+
+    private fun createFingerprintSensor() {
+        if (null != fingerprintSensor) {
+            FingprintFactory.destroy(fingerprintSensor)
+            fingerprintSensor = null
+        }
+        // Define output log level
+        LogHelper.setLevel(Log.VERBOSE)
+        LogHelper.setNDKLogLevel(Log.ASSERT)
+        // Start fingerprint sensor
+        val deviceParams = HashMap<String?, Any?>()
+        //set vid
+        deviceParams[ParameterHelper.PARAM_KEY_VID] = usb_vid
+        //set pid
+        deviceParams[ParameterHelper.PARAM_KEY_PID] = usb_pid
+        fingerprintSensor = FingprintFactory.createFingerprintSensor(
+            applicationContext,
+            TransportType.USB,
+            deviceParams
+        )
+    }
+
+    fun doRegister(template: ByteArray?) {
+        val bufids = ByteArray(256)
+        var ret = ZKFingerService.identify(template, bufids, 70, 1)
+        if (ret > 0) {
+            val strRes = String(bufids).split("\t".toRegex()).dropLastWhile { it.isEmpty() }
+                .toTypedArray()
+            setResult("the finger already enroll by " + strRes[0] + ",cancel enroll")
+            bRegister = false
+            enroll_index = 0
+            return
+        }
+        if (enroll_index > 0 && (ZKFingerService.verify(
+                regtemparray.get(enroll_index - 1),
+                template
+            ).also {
+                ret = it
+            }) <= 0
+        ) {
+            setResult("please press the same finger 3 times for the enrollment, cancel enroll, socre=$ret")
+            bRegister = false
+            enroll_index = 0
+            return
+        }
+        System.arraycopy(template, 0, regtemparray.get(enroll_index), 0, 2048)
+        enroll_index++
+        if (enroll_index == ENROLL_COUNT) {
+            bRegister = false
+            enroll_index = 0
+            val regTemp = ByteArray(2048)
+            if (0 < (ZKFingerService.merge(
+                    regtemparray.get(0),
+                    regtemparray.get(1),
+                    regtemparray.get(2),
+                    regTemp
+                ).also {
+                    ret = it
+                })
+            ) {
+                var retVal = 0
+                retVal = ZKFingerService.save(regTemp, strUid)
+                if (0 == retVal) {
+                    val strFeature = Base64.encodeToString(regTemp, 0, ret, Base64.NO_WRAP)
+                    println("haha : $strFeature")
+//                    dbManager.insertUser(strUid, strFeature)
+                    setResult("enroll succ")
+                } else {
+                    setResult("enroll fail, add template fail, ret=$retVal")
+                }
+            } else {
+                setResult("enroll fail")
+            }
+            bRegister = false
+        } else {
+            setResult("You need to press the " + (3 - enroll_index) + " times fingerprint")
+        }
+    }
+
+    private fun setResult(result: String) {
+        val mStrText = result
+        runOnUiThread { mBinding?.txtResult?.setText(mStrText) }
+    }
+
+    fun doIdentify(template: ByteArray?) {
+        val bufids = ByteArray(256)
+        val ret = ZKFingerService.identify(template, bufids, 70, 1)
+        if (ret > 0) {
+            val strRes = String(bufids).split("\t".toRegex()).dropLastWhile { it.isEmpty() }
+                .toTypedArray()
+            setResult("identify succ, userid:" + strRes[0].trim { it <= ' ' } + ", score:" + strRes[1].trim { it <= ' ' })
+        } else {
+            setResult("identify fail, ret=$ret")
+        }
+    }
+
+    override fun onDestroy() {
+        super.onDestroy()
+        if (bStarted) {
+            closeDevice()
+        }
+        zkusbManager!!.unRegisterUSBPermissionReceiver()
+    }
+}

+ 41 - 0
app/src/main/java/com/grkj/iscs/view/activity/test/fingerprint/PermissionUtils.java

@@ -0,0 +1,41 @@
+package com.grkj.iscs.view.activity.test.fingerprint;
+
+import android.app.Activity;
+import android.content.pm.PackageManager;
+import android.os.Build;
+
+import androidx.core.app.ActivityCompat;
+
+import java.util.ArrayList;
+
+/**
+ * @author Magic
+ * @version 创建时间:2020/05/22 上午 9:44
+ */
+public class PermissionUtils {
+
+    public static ArrayList<String> checkPermissions(Activity activity, String[] permissions) {
+        if (activity == null) {
+            throw new NullPointerException("activity can't be null");
+        }
+
+        ArrayList<String> deniedPermissions = new ArrayList<>();
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
+            return deniedPermissions;
+        }
+        for (String permission : permissions) {
+            if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
+                deniedPermissions.add(permission);
+            }
+        }
+        return deniedPermissions;
+    }
+
+
+    public static void requestPermission(Activity activity, String[] permissions, int requestCode) {
+        if (activity == null) {
+            throw new NullPointerException("activity can't be null");
+        }
+        ActivityCompat.requestPermissions(activity, permissions, requestCode);
+    }
+}

+ 162 - 0
app/src/main/java/com/grkj/iscs/view/activity/test/fingerprint/ZKUSBManager/ZKUSBManager.java

@@ -0,0 +1,162 @@
+package com.grkj.iscs.view.activity.test.fingerprint.ZKUSBManager;
+
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbManager;
+
+import androidx.annotation.NonNull;
+
+import java.util.Random;
+
+/**
+ * usb permission and hotplug
+ */
+public class ZKUSBManager {
+    //usb's vendor id for zkteco
+    private int vid = 0x1b55;
+    //usb's product id
+    private int pid = 0;
+    //application context
+    private Context mContext = null;
+
+    /////////////////////////////////////////////
+    //for usb permission
+    private static final String SOURCE_STRING = "0123456789-_abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
+    private static final int DEFAULT_LENGTH = 16;
+    private String ACTION_USB_PERMISSION;
+    private boolean mbRegisterFilter = false;
+    private ZKUSBManagerListener zknirusbManagerListener = null;
+
+    private BroadcastReceiver usbMgrReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            if (ACTION_USB_PERMISSION.equals(action))
+            {
+                UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+                if (device.getVendorId() == vid && device.getProductId() == pid) {
+                    if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
+                        zknirusbManagerListener.onCheckPermission(0);
+                    } else {
+                        zknirusbManagerListener.onCheckPermission(-2);
+                    }
+                }
+            }
+            else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action))
+            {
+                UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+                if (device.getVendorId() == vid && device.getProductId() == pid) {
+                    zknirusbManagerListener.onUSBArrived(device);
+                }
+            }
+            else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action))
+            {
+                UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+                if (device.getVendorId() == vid && device.getProductId() == pid) {
+                    zknirusbManagerListener.onUSBRemoved(device);
+                }
+            }
+        }
+    };
+
+
+    private boolean isNullOrEmpty(String target) {
+        if (null == target || "".equals(target) || target.isEmpty()) {
+            return true;
+        }
+        return false;
+    }
+
+    private String createRandomString(String source, int length) {
+        if (this.isNullOrEmpty(source)) {
+            return "";
+        }
+
+        StringBuffer result = new StringBuffer();
+        Random random = new Random();
+
+        for(int index = 0; index < length; index++) {
+            result.append(source.charAt(random.nextInt(source.length())));
+        }
+        return result.toString();
+    }
+
+    public boolean registerUSBPermissionReceiver()
+    {
+        if (null == mContext || mbRegisterFilter)
+        {
+            return false;
+        }
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(ACTION_USB_PERMISSION);
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+        mContext.registerReceiver(usbMgrReceiver, filter);
+        mbRegisterFilter = true;
+        return true;
+    }
+
+    public void unRegisterUSBPermissionReceiver()
+    {
+        if (null == mContext || !mbRegisterFilter)
+        {
+            return;
+        }
+        mContext.unregisterReceiver(usbMgrReceiver);
+        mbRegisterFilter = false;
+    }
+
+
+    //End USB Permission
+    /////////////////////////////////////////////
+
+    public ZKUSBManager(@NonNull Context context, @NonNull ZKUSBManagerListener listener)
+    {
+        super();
+        if (null == context || null == listener)
+        {
+            throw new NullPointerException("context or listener is null");
+        }
+        zknirusbManagerListener = listener;
+        ACTION_USB_PERMISSION = createRandomString(SOURCE_STRING, DEFAULT_LENGTH);
+        mContext = context;
+    }
+
+    //0 means success
+    //-1 means device no found
+    //-2 means device no permission
+    public void initUSBPermission(int vid, int pid){
+        UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
+        UsbDevice usbDevice = null;
+        for (UsbDevice device : usbManager.getDeviceList().values()) {
+            int device_vid = device.getVendorId();
+            int device_pid = device.getProductId();
+            if (device_vid == vid && device_pid == pid)
+            {
+                usbDevice = device;
+                break;
+            }
+        }
+        if (null == usbDevice)
+        {
+            zknirusbManagerListener.onCheckPermission(-1);
+            return;
+        }
+        this.vid = vid;
+        this.pid = pid;
+        if (!usbManager.hasPermission(usbDevice))
+        {
+            Intent intent = new Intent(this.ACTION_USB_PERMISSION);
+            PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
+            usbManager.requestPermission(usbDevice, pendingIntent);
+        }
+        else {
+            zknirusbManagerListener.onCheckPermission(0);
+        }
+    }
+
+}

+ 15 - 0
app/src/main/java/com/grkj/iscs/view/activity/test/fingerprint/ZKUSBManager/ZKUSBManagerListener.java

@@ -0,0 +1,15 @@
+package com.grkj.iscs.view.activity.test.fingerprint.ZKUSBManager;
+
+import android.hardware.usb.UsbDevice;
+
+public interface ZKUSBManagerListener
+{
+    //0 means success
+    //-1 means device no found
+    //-2 means device no permission
+    void onCheckPermission(int result);
+
+    void onUSBArrived(UsbDevice device);
+
+    void onUSBRemoved(UsbDevice device);
+}

BIN
app/src/main/jniLibs/arm64-v8a/libslkidcap.so


BIN
app/src/main/jniLibs/arm64-v8a/libzkalg12.so


BIN
app/src/main/jniLibs/arm64-v8a/libzkfinger10.so


BIN
app/src/main/jniLibs/arm64-v8a/libzksensorcore.so


BIN
app/src/main/jniLibs/armeabi-v7a/libslkidcap.so


BIN
app/src/main/jniLibs/armeabi-v7a/libzkalg12.so


BIN
app/src/main/jniLibs/armeabi-v7a/libzkfinger10.so


BIN
app/src/main/jniLibs/armeabi-v7a/libzksensorcore.so


+ 105 - 0
app/src/main/res/layout/activity_finger_print.xml

@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/main"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal"
+    tools:context=".view.activity.test.fingerprint.FingerPrintActivity">
+
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="1"
+        android:orientation="vertical">
+        <Button
+            android:id="@+id/start"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Start"
+            android:textSize="10sp" />
+
+        <Button
+            android:id="@+id/stop"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Stop"
+            android:textSize="10sp" />
+
+        <Button
+            android:id="@+id/register"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Register"
+            android:textSize="10sp" />
+
+        <Button
+            android:id="@+id/identify"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Identify"
+            android:textSize="10sp" />
+
+
+        <Button
+            android:id="@+id/delete"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Delete"
+            android:textSize="10sp" />
+
+        <Button
+            android:id="@+id/clear"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Clear"
+            android:textSize="10sp" />
+
+        <Button
+            android:id="@+id/exit"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Exit"
+            android:textSize="10sp" />
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="1"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/txtResult"
+            android:layout_width="match_parent"
+            android:layout_height="40dp"
+            android:text=""
+            android:textSize="20sp"/>
+
+        <ImageView
+            android:id="@+id/imageFP"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" />
+    </LinearLayout>
+</LinearLayout>

+ 26 - 9
app/src/main/res/layout/activity_main.xml

@@ -127,13 +127,30 @@
             android:layout_margin="5dp"/>
     </LinearLayout>
 
-    <Button
-        android:id="@+id/face"
-        android:layout_width="wrap_content"
-        android:layout_height="50dp"
-        android:layout_margin="5dp"
-        android:minWidth="0dp"
-        android:minHeight="0dp"
-        android:text="Face"
-        android:textSize="10sp" />
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:gravity="center">
+
+        <Button
+            android:id="@+id/face"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Face"
+            android:textSize="10sp" />
+
+        <Button
+            android:id="@+id/finger"
+            android:layout_width="wrap_content"
+            android:layout_height="50dp"
+            android:layout_margin="5dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="FingerPrint"
+            android:textSize="10sp" />
+    </LinearLayout>
 </LinearLayout>