基于厂家提供的例子 android060demo.rar
// FingerPrintFeature.java
//依赖 demo 的 andriod060.java 和 za_finger.java;引入库 libandroid_060.so;把demo中的权限,加入项目
//另 closeDevice方法 调用时发现有问题并没有调用,只open然后读取指纹发现没有问题
package com.renhe.za.fingerPrintApi;
import io.dcloud.DHInterface.IWebview;
import io.dcloud.DHInterface.StandardFeature;
import io.dcloud.util.JSUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.za.android060;
import com.zafinger.ZA_finger;
public class FingerPrintFeature extends StandardFeature{
public void openDevice(IWebview pWebview, JSONArray array){
int DEV_ADDR = 0xffffffff;
android060 a6= new android060();
try{
//a6.card_power_off(60, 3);
ZA_finger.fppower(1);
//ZA_finger.cardpower(1);
android.os.SystemClock.sleep(1000);
int status = a6.ZAZOpenDeviceEx(-1,2, 3, 12, 0, 0);
if(status!=1){
JSUtil.execCallback(pWebview, array.optString(0), "打开设备失败", JSUtil.ERROR, false);
return;
}
JSUtil.execCallback(pWebview, array.optString(0), "打开设备成功", JSUtil.OK, false);
}catch(Exception ex){
JSUtil.execCallback(pWebview, array.optString(0), "打开设备异常", JSUtil.ERROR, false);
return;
}
}
public void closeDevice(IWebview pWebview, JSONArray array)
{
int DEV_ADDR = 0xffffffff;
android060 a6= new android060();
try{
a6.ZAZCloseDeviceEx();
ZA_finger.fppower(0);
//ZA_finger.cardpower(0);
JSUtil.execCallback(pWebview, array.optString(0), "关闭设备成功", JSUtil.OK, false);
}catch(Exception ex){
JSUtil.execCallback(pWebview, array.optString(0), "关闭设备失败", JSUtil.ERROR, false);
}
}
public void doFingerPrint(IWebview pWebview, JSONArray array){
int DEV_ADDR = 0xffffffff;
android060 a6= new android060();
try{
int nRet = 0;
nRet = a6.ZAZGetImage(DEV_ADDR);
if(nRet == 0){
int[] len = { 0, 0 };
char[] Image = new char[256 * 288];
a6.ZAZUpImage(DEV_ADDR, Image, len);
String fingerPrintPath = android.os.Environment.getExternalStorageDirectory().getPath()+"/fingerPrint.bmp";
a6.ZAZImgData2BMP(Image, fingerPrintPath);
nRet= a6.ZAZGenChar(DEV_ADDR, a6.CHAR_BUFFER_A);
if(nRet ==a6.PS_OK){
int[] iTempletLength = { 0, 0 };
byte[] pTemplet = new byte[512];
nRet=a6.ZAZUpChar(DEV_ADDR,a6.CHAR_BUFFER_A, pTemplet, iTempletLength);
if(nRet ==a6.PS_OK){
JSONObject obj = new JSONObject();
obj.put("fingerPrintCode", charToHexString(pTemplet));
obj.put("fingerPrintPath", fingerPrintPath);
JSUtil.execCallback(pWebview, array.optString(0), obj, JSUtil.OK, false);
}else{
JSUtil.execCallback(pWebview, array.optString(0), "生成指纹特征码失败", JSUtil.ERROR, false);
}
}else{
JSUtil.execCallback(pWebview, array.optString(0), "指纹特征太差,重新录入", JSUtil.ERROR, false);
}
}else if(nRet==a6.PS_NO_FINGER){
JSUtil.execCallback(pWebview, array.optString(0), "未按手指", JSUtil.ERROR, false);
}else {
JSUtil.execCallback(pWebview, array.optString(0), "读取指纹失败", JSUtil.ERROR, false);
}
}catch(Exception ex){
JSUtil.execCallback(pWebview, array.optString(0), "读取指纹异常", JSUtil.ERROR, false);
}
}
private String charToHexString(byte[] val) {
String temp="";
for(int i=0;i<val.length;i++)
{
String hex = Integer.toHexString(0xff & val[i]);
if (hex.length() == 1) {
hex = '0' + hex;
}
temp += hex.toUpperCase();
}
return temp;
}
}
4 个评论
要回复文章请先登录或注册
蔡繁荣
fz (作者)
fz (作者)
fz (作者)