Reputation: 1
I developed an application for **android **where i am getting Finger Print using **SecuGen **Pro 20 device. Samsung device capture the finger print image. But other device can not capture image (such as: One plus, Redmi, Xiaomi, Techno etc. device)
Initialization part into onCreate() section
// fingerPrintEnable()
mPermissionIntent = PendingIntent.getBroadcast(
requireContext(),
0,
Intent(Const.ACTION_USB_PERMISSION),
PendingIntent.FLAG_IMMUTABLE
)
filter = IntentFilter(Const.ACTION_USB_PERMISSION)
// registerReceiver(usbReceiver, filter)
jsgfpLib = JSGFPLib(requireContext().getSystemService(Context.USB_SERVICE) as UsbManager)
bSecuGenDeviceOpened = false
usbPermissionRequested = false
autoOn = SGAutoOnEventNotifier(jsgfpLib, this)
Image capture code
mRegisterImage = ByteArray(mImageWidth * mImageHeight)
var result = jsgfpLib.GetImage(mRegisterImage)
result = jsgfpLib.GetMaxTemplateSize(mMaxTemplateSize)
minBuffer = ByteArray(mMaxTemplateSize[0])
jsgfpLib.SetTemplateFormat(SGFDxTemplateFormat.TEMPLATE_FORMAT_ANSI378)
jsgfpLib.GetImageQuality(
mImageWidth.toLong(),
mImageHeight.toLong(),
mRegisterImage,
quality1
)
var fpInfo: SGFingerInfo? = SGFingerInfo()
fpInfo?.FingerNumber = 1
fpInfo?.ImageQuality = quality1[0]
fpInfo?.ImpressionType = SGImpressionType.SG_IMPTYPE_LP
fpInfo?.ViewNumber = 1
jsgfpLib.CreateTemplate(fpInfo, mRegisterImage, minBuffer)
val size = IntArray(1)
jsgfpLib.GetTemplateSize(minBuffer, size)
imgViewCapture.setImageBitmap(this.toGrayscale(mRegisterImage!!))
USB Permission Code
private val usbReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent?.action
if (Const.ACTION_USB_PERMISSION == action) {
synchronized(this) {
val device: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
Log.e("USB BroadcastReceiver VID", "" + device.vendorId)
Log.e("USB BroadcastReceiver VID", "" + device.productId)
} else {
Log.e("TAG", "mUsbReceiver.onReceive() Device is null")
}
} else
Log.e(
"TAG",
"mUsbReceiver.onReceive() permission denied for device $device"
)
}
}
}
SecuGen permission
var errorValue = jsgfpLib.Init(SGFDxDeviceName.SG_DEV_AUTO)
if (errorValue != SGFDxErrorCode.SGFDX_ERROR_NONE) {
if (secuGenDialog == 1) {
val dlgAlert = AlertDialog.Builder(requireContext())
if (errorValue == SGFDxErrorCode.SGFDX_ERROR_DEVICE_NOT_FOUND) {
dlgAlert.setMessage("The attached fingerprint device is not supported on Android")
} else {
fingerPageVisibilityGone()
dlgAlert.setMessage("Fingerprint device initialization failed!")
}
dlgAlert.setTitle("SecuGen Fingerprint SDK")
dlgAlert.setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
}
dlgAlert.setCancelable(false)
// dlgAlert.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int -> requireActivity().finish() }
dlgAlert.create().show()
}
} else {
val usbDevice = jsgfpLib.GetUsbDevice()
if (usbDevice == null) {
if (secuGenDialog == 1) {
fingerPageVisibilityGone()
val dlgAlert = AlertDialog.Builder(requireContext())
dlgAlert.setMessage("SecuGen fingerprint sensor not found!")
dlgAlert.setTitle("SecuGen Fingerprint SDK")
dlgAlert.setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
}
dlgAlert.setCancelable(false)
dlgAlert.create().show()
}
} else {
var hasPermission = jsgfpLib.GetUsbManager().hasPermission(usbDevice)
if (!hasPermission) {
if (!usbPermissionRequested) {
usbPermissionRequested = true
jsgfpLib.GetUsbManager().requestPermission(usbDevice, mPermissionIntent)
} else {
//wait up to 20 seconds for the system to grant USB permission
hasPermission = jsgfpLib.GetUsbManager().hasPermission(usbDevice)
var i = 0
while (!hasPermission && i <= 40) {
++i
hasPermission = jsgfpLib.GetUsbManager().hasPermission(usbDevice)
try {
Thread.sleep(500)
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
}
}
if (hasPermission) {
errorValue = jsgfpLib.OpenDevice(0)
if (errorValue == SGFDxErrorCode.SGFDX_ERROR_NONE) {
bSecuGenDeviceOpened = true
val deviceInfo = SGDeviceInfoParam()
jsgfpLib.GetDeviceInfo(deviceInfo)
mImageWidth = deviceInfo.imageWidth
mImageHeight = deviceInfo.imageHeight
mImageDPI = deviceInfo.imageDPI
jsgfpLib.SetTemplateFormat(SGFDxTemplateFormat.TEMPLATE_FORMAT_ANSI378)
jsgfpLib.GetMaxTemplateSize(mMaxTemplateSize)
autoOn.start()
}
}
}
}
But I am getting crash from other device Like Realme, mi, Techno, Oneplus etc. Crash occur and give me a message Null Pointer Exception.
java.lang.NullPointerException: Attempt to invoke virtual method 'long SecuGen.Driver.SmartCapture3Fdu05.Start(int, boolean)' on a null object reference
I attach an image of my code. I am getting crash in the result line.
I do not find any solution.
Please help me. [enter image description here][1]
I tried the given image code. But it's return null and app is crash. I setup the SDK properly. But for few device (such as: Oneplus, Realme, mi, Techno, etc) i am getting the null.
I need the suggestion where is code error. How can i solve this problem .
Upvotes: 0
Views: 94