Git Product home page Git Product logo

rxfingerprinter's Introduction

RxFingerPrinter

Build Status

用rxjava简单封装了指纹识别,顺便撸了一个指纹控件

image

Setup

测试机型推荐android版本6.0以上且具有指纹模块。

在项目build.gradle中配置 :

repositories {
    jcenter() // If not already there
}

在Module中build.gradle中配置 :

dependencies {
    compile  'com.zwh:RxFingerPrinter:1.0.1'
}

Usage

创建一个 RxFingerPrinter实例 :

RxFingerPrinter rxFingerPrinter = new RxFingerPrinter(this); // where this is an Activity instance

在需要开启指纹识别的地方执行begin方法并订阅:

// 可以在oncreat方法中执行
Subscription subscription =
     rxFingerPrinter
    .begin()
    .subscribe(new Subscriber<Boolean>() {
      @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){
          Toast.makeText(MainActivity.this, "指纹识别成功", Toast.LENGTH_SHORT).show();
        }else {
          Toast.makeText(MainActivity.this, "指纹识别失败", Toast.LENGTH_SHORT).show();
        }
      }
    });
    rxfingerPrinter.addSubscription(this,subscription); //不要忘记把订阅返回的subscription添加到rxfingerPrinter里

在onDestroy方法中执行取消订阅

//
    @Override
    protected void onDestroy() {
        super.onDestroy();
        rxfingerPrinter.unSubscribe(this);
    }

用FPerException封装了一下指纹识别时可能出现的异常,可以在订阅的Subscriber的onError(Throwable e)中获取该异常

@Override
      public void onError(Throwable e) {
          if(e instanceof FPerException){//判断该异常是否为FPerException
            Toast.makeText(MainActivity.this,((FPerException) e).getDisplayMessage(),Toast.LENGTH_SHORT).show();
         }

可以根据((FPerException) e).getCode() 来获取对应的错误码,也可以直接调用((FPerException) e).getDisplayMessage()提示默认的错误信息。

public String getDisplayMessage() {
        switch (code) {
            case SYSTEM_API_ERROR:
                return "系统API小于23";
            case PERMISSION_DENIED_ERROE:
                return "没有指纹识别权限";
            case HARDWARE_MISSIING_ERROR:
                return "没有指纹识别模块";
            case KEYGUARDSECURE_MISSIING_ERROR:
                return "没有开启锁屏密码";
            case NO_FINGERPRINTERS_ENROOLED_ERROR:
                return "没有指纹录入";
            case FINGERPRINTERS_FAILED_ERROR:
                return "指纹认证失败";
            default:
                return "";
        }
    }

rxfingerprinter's People

Contributors

zweihui avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.