Android指纹识别源码_指纹识别解锁开发Demo下载
程序员文章站
2022-02-02 09:46:53
...
目前大多数手机已经添支持指纹功能了、目前都是使用在指纹解锁、指纹支付、指纹登录、那么我们自己开发的App如果想要实现指纹设别功能需要怎么做呢、今天就给大家分享一个添加库、在app登录界面使用指纹识别模块实现指纹登陆、或者是使用指纹进行其它功能是身价验证、效果图如下
Java代码
private FingerPrinterView fingerPrinterView; private int fingerErrorNum = 0; // 指纹错误次数 RxFingerPrinter rxfingerPrinter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); fingerPrinterView = (FingerPrinterView) findViewById(R.id.fpv); fingerPrinterView.setOnStateChangedListener(new FingerPrinterView.OnStateChangedListener() { @Override public void onChange(int state) { if (state == FingerPrinterView.STATE_CORRECT_PWD) { fingerErrorNum = 0; Toast.makeText(MainActivity.this, "指纹识别成功", Toast.LENGTH_SHORT).show(); } if (state == FingerPrinterView.STATE_WRONG_PWD) { Toast.makeText(MainActivity.this, "指纹识别失败,还剩" (5-fingerErrorNum) "次机会", Toast.LENGTH_SHORT).show(); fingerPrinterView.setState(FingerPrinterView.STATE_NO_SCANING); } } }); rxfingerPrinter = new RxFingerPrinter(this); findViewById(R.id.btn_open).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fingerErrorNum = 0; rxfingerPrinter.unSubscribe(this); Subscription subscription = rxfingerPrinter.begin().subscribe(new Subscriber<Boolean>() { @Override public void onStart() { super.onStart(); if (fingerPrinterView.getState() == FingerPrinterView.STATE_SCANING) { return; } else if (fingerPrinterView.getState() == FingerPrinterView.STATE_CORRECT_PWD || fingerPrinterView.getState() == FingerPrinterView.STATE_WRONG_PWD) { fingerPrinterView.setState(FingerPrinterView.STATE_NO_SCANING); } else { fingerPrinterView.setState(FingerPrinterView.STATE_SCANING); } } @Override public void onCompleted() { } @Override public void onError(Throwable e) { if(e instanceof FPerException){ Toast.makeText(MainActivity.this,((FPerException) e).getDisplayMessage(),Toast.LENGTH_SHORT).show(); } } @Override public void onNext(Boolean aBoolean) { if(aBoolean){ fingerPrinterView.setState(FingerPrinterView.STATE_CORRECT_PWD); }else{ fingerErrorNum ; fingerPrinterView.setState(FingerPrinterView.STATE_WRONG_PWD); } } }); rxfingerPrinter.addSubscription(this,subscription); } }); } @Override protected void onDestroy() { super.onDestroy(); rxfingerPrinter.unSubscribe(this); }
XML代码
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@ id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.zwh.rxfingerprinter.MainActivity"> <android.support.v7.widget.CardView android:id="@ id/cv" android:layout_width="80dp" android:layout_height="80dp" android:layout_centerInParent="true" app:cardBackgroundColor="@android:color/white" app:cardCornerRadius="20dp" app:cardElevation="5dp"> <com.zwh.rxfingerprinter.FingerPrinterView android:id="@ id/fpv" android:layout_width="70dp" android:layout_height="70dp" android:layout_gravity="center" /> </android.support.v7.widget.CardView> <Button android:id="@ id/btn_open" android:layout_width="60dp" android:layout_height="40dp" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginTop="30dp" android:text="开启" android:textSize="14sp" /> </RelativeLayout>
Android6.0指纹识别开发实例源代码下载链接: Android指纹识别开发 密码: aabs
上一篇: 防止vuejs在解析时出现闪烁_解决vue渲染时闪烁
下一篇: ApplicationContext
推荐阅读