GithubHelp home page GithubHelp logo

shinichi52 / react-native-touch-id-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kalontech/react-native-touch-id-android

0.0 2.0 0.0 28.42 MB

Touch ID module for Android

License: MIT License

Shell 0.09% Java 99.13% JavaScript 0.54% Python 0.07% Objective-C 0.18%

react-native-touch-id-android's Introduction

react-native-touch-id-android

npm version npm version npm Build Status

Fingerprint identity for Android based on https://github.com/ajalt/reprint

NOTES:

Demo

Installation Android

Tested only on RN version > 0.40

  1. npm install react-native-touch-id-android --save

  2. react-native link react-native-touch-id-android

  3. android/build.gradle (not android/app/build.gradle, pay attention):

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven { url "https://jitpack.io" }            // <--- add this line
    }
}
  1. android/app/src/main/java/<YOUR-APP-FOLDER>/MainApplication file, check if you already have this lines:
import com.github.ajalt.reprint.core.Reprint;      // <- add this line
import co.eleken.react_native_touch_id_android.FingerprintPackage;    // <- add this line

public class MainApplication extends Application implements ReactApplication {

...

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new FingerprintPackage()     // <- add this line
      );
    }
    
  };

  @Override
  public void onCreate() {
    super.onCreate();
    Reprint.initialize(this); // <- add this line
  }

...
  1. Enable fingerprint in phone's settings

Usage

  1. Finger.isSensorAvailable(): Promise returns true if success and string error in other cases (including case when you have sensor, but not enabled it in your phone's settings)
Finger.isSensorAvailable()
    .then((isAvailable) => {   })
    .catch(error => {   });
  1. Finger.requestTouch(): Promise returns true if success and string error in other cases.
Finger.requestTouch()
    .then(success => {  })
    .catch(error => {  });
  1. Finger.dismiss() if you open sensor and want to close it before touching (like when close app or dialog)

Example

import Finger from 'react-native-touch-id-android'

export default class TouchTest extends Component {

  componentDidMount() {
    Finger.isSensorAvailable()
      .then((isAvailable) => {
        ToastAndroid.show('Sensor is available and is waiting for touch', ToastAndroid.SHORT);
        this.touchAuth()
      })
      .catch(error => {
        ToastAndroid.show(error, ToastAndroid.SHORT);
      });
  }

  touchAuth(){
    Finger.requestTouch()
      .then(success => {
        ToastAndroid.show('Access granted', ToastAndroid.SHORT);
      })
      .catch(error => {
        ToastAndroid.show(error, ToastAndroid.SHORT);
      });
  }

  render() {
    return (    

        ...

    );
  }

  componentWillUnmount(){
    Finger.dismiss()
  }
}

Troubleshooting

If you made 5 wrong fingerprint attempts, Android Fingerprint API requires some time to continue work with sensor. In that case Finger.requestTouch() returns error LOCKED_OUT, so it would be good to make user awared that senser is temporary unavailable (near 30 seconds).

Questions or suggestions?

Feel free to open an issue

react-native-touch-id-android's People

Contributors

marcorm avatar vasiliev90 avatar

Watchers

 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.