rxbiometric

RxJava and RxKotlin bindings for Biometric Prompt on Android

License

License

GroupId

GroupId

com.github.pwittchen
ArtifactId

ArtifactId

rxbiometric
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

rxbiometric
RxJava and RxKotlin bindings for Biometric Prompt on Android
Project URL

Project URL

https://github.com/pwittchen/RxBiometric
Source Code Management

Source Code Management

https://github.com/pwittchen/RxBiometric

Download rxbiometric

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.pwittchen/rxbiometric/ -->
<dependency>
    <groupId>com.github.pwittchen</groupId>
    <artifactId>rxbiometric</artifactId>
    <version>0.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.pwittchen/rxbiometric/
implementation 'com.github.pwittchen:rxbiometric:0.1.0'
// https://jarcasting.com/artifacts/com.github.pwittchen/rxbiometric/
implementation ("com.github.pwittchen:rxbiometric:0.1.0")
'com.github.pwittchen:rxbiometric:aar:0.1.0'
<dependency org="com.github.pwittchen" name="rxbiometric" rev="0.1.0">
  <artifact name="rxbiometric" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.pwittchen', module='rxbiometric', version='0.1.0')
)
libraryDependencies += "com.github.pwittchen" % "rxbiometric" % "0.1.0"
[com.github.pwittchen/rxbiometric "0.1.0"]

Dependencies

compile (6)

Group / Artifact Type Version
io.reactivex.rxjava2 : rxjava jar 2.2.0
io.reactivex.rxjava2 : rxandroid jar 2.0.2
io.reactivex.rxjava2 : rxkotlin jar 2.3.0
androidx.annotation » annotation jar 1.0.1
androidx.biometric » biometric jar 1.0.0-alpha03
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.3.0

Project Modules

There are no modules declared in this project.

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.

Versions

Version
0.1.0
0.0.1