Coder Social home page Coder Social logo

pwittchen / rxbiometric Goto Github PK

View Code? Open in Web Editor NEW
301.0 7.0 28.0 560 KB

☝️ RxJava and RxKotlin bindings for Biometric Prompt (Fingerprint Scanner) on Android

License: Apache License 2.0

Kotlin 98.98% Shell 1.02%
android biometric prompt fingerprint rxjava rxjava2 rxandroid rxandroid2 rxkotlin rxkotlin-android

rxbiometric's Introduction

logo

RxBiometric Build Status Maven Central Android Arsenal

RxJava and RxKotlin bindings for Biometric Prompt (Fingerprint Scanner) on Android (added in Android 9 Pie, API Level 28+)

If your app is drawing its own fingerprint auth dialogs, you should switch to using the BiometricPrompt API as soon as possible.

It's an official statement from Google Android Developers Blog. RxBiometric helps you to do that via RxJava stream!

Contents

Usage

Simple library usage in Kotlin looks as follows:

RxBiometric
  .title("title")
  .description("description")
  .negativeButtonText("cancel")
  .negativeButtonListener(DialogInterface.OnClickListener { _, _ ->
    showMessage("cancel")
  })
  .executor(mainExecutor)
  .build()
  .authenticate(context)
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribeBy(
    onComplete = { showMessage("authenticated!") },
    onError = { showMessage("error") }
  )

Library also have validation method in the Preconditions class, which you can use to verify if you're able to use Biometric.

Preconditions.hasBiometricSupport(context)

There's also RxPreconditions class, which has the same method wrapped in RxJava Single<Boolean> type, which you can use to create fluent data flow like in the example below

RxPreconditions
  .hasBiometricSupport(context)
  .flatMapCompletable {
    if (!it) Completable.error(BiometricNotSupported())
    else
      RxBiometric
        .title("title")
        .description("description")
        .negativeButtonText("cancel")
        .negativeButtonListener(DialogInterface.OnClickListener { _, _ ->
          showMessage("cancel")
        })
        .executor(mainExecutor)
        .build()
        .authenticate(context)
  }
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribeBy(
    onComplete = { showMessage("authenticated!") },
    onError = {
      when (it) {
        is AuthenticationError -> showMessage("error")
        is AuthenticationFail -> showMessage("fail")
        is AuthenticationHelp -> showMessage("help")
        is BiometricNotSupported -> showMessage("biometric not supported")
        else -> showMessage("other error")
      }
    }
  )

If you want to create your own CryptoObject and use it during authentication, then you can call authenticate(context, cryptoObject) method instead of authenticate(context).

Of course, don't forget to dispose Disposable appropriately in the Activity Lifecycle.

Library can be used in the Java projects as well. Idea is the same, just syntax will be a bit different.

Examples

Complete example of the working application can be found in the kotlin-app directory.

Download

You can depend on the library through Gradle:

dependencies {
  implementation 'com.github.pwittchen:rxbiometric:0.1.0'
}

Tests

Tests are available in library/src/test/kotlin/ directory and can be executed on JVM without any emulator or Android device from Android Studio or CLI with the following command:

./gradlew test

Code style

Code style used in the project is called SquareAndroid from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.

Static code analysis

Static code analysis runs Checkstyle, PMD, Lint and Detekt. It can be executed with command:

./gradlew check

Reports from analysis are generated in library/build/reports/ directory.

JavaDoc

Documentation can be generated as follows:

./gradlew dokka

Output will be generated in library/build/javadoc

JavaDoc can be viewed on-line at https://pwittchen.github.io/RxBiometric/library/

Changelog

See CHANGELOG.md file.

Releasing

See RELEASING.md file.

Mentions

References

License

Copyright 2018 Piotr Wittchen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

rxbiometric's People

Contributors

bagbyte avatar dependabot-preview[bot] avatar ksc91u avatar natiginfo avatar pwittchen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxbiometric's Issues

Dialog Dismiss

If we tap outside Biometric Dialog it is dismissing. It should remain as it is.

cancellationSignal is missing

In Readme file, it's mentioned that we can set cancellation signal using cancellationSignal(cancellationSignal), however, it's missing from library.

Release 0.1.0

Release notes:

  • used androidx.biometrics to support devices since Android 6 (Marshmallow) - issue #1, PR #9
  • removed Preconditions#isAtLeastAndroidPie() method
  • removed Preconditions#canHandleBiometric(context) method
  • removed RxPreconditions#isAtLeastAndroidPie() method
  • removed RxPreconditions#canHandleBiometric(context) method

Things to do:

  • bump library version
  • upload archives
  • close and release artifact
  • update JavaDocs on gh-pages
  • update CHANGELOG.md
  • update version in README.md
  • create GitHub release

Get Callback only once when authenticate finger

Hi,

Device: Gionee A1
OS: 7.0

I try to Authenticate finger print but i get callback only one time.
Click on Authenticate Button.
Dialog pop out.
touch the wrong finger dialog prompt for wrong finger and get callback on failed
2nd time again touch wrong or right finger not get callback in MainActivity subscribeby method

Release 0.0.1

Things to do:

  • bump library version
  • update JavaDoc on gh-pages
  • upload archives to Maven Central Repository
  • close and release artifact
  • update CHANGELOG.md after Maven Sync
  • bump library version in README.md after Maven Sync
  • create new GitHub release

Add convenience method for validation to RxBiometric class

Add convenience method for validation to RxBiometric class, so library users won't have to call canHandleBiometric(context) explicitely, flatMap(...) operation can be hidden under the hood and we can throw BiometricNotSupported when needed.

It could look like that in the API:

RxBiometric
  .enableValidation()
  . // rest of the code goes here
  ...

onComplete is not being called

When I try to authenticate via fingerprint, onComplete is being invoked. After that, if I try to authenticate again successfully, onComplete is not being invoked.

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.