Open sourcing RxSmartLock
About a month ago we open sourced RxSmartLock. In a previous post we described how RxSmartLock works under the hood (using a transparent activity). In this blog post we focus on how to use RxSmartLock.
The public API is kept very simple, expressive and explicit. As a developer who uses RxSmartLock in your app you only have to know about
So how would you store your username and password? As a first step you need to create a Credential and setup user data such as name and password. Then pass it to the method
RxGoogleSmartLockManager.storeCredentials(context, credential) along with the context. In the code below you can see an example for storing credentials:
Once credentials are stored you should be able to retrieve them following the example code:
If retrieving credentials fails, it is possible to fetch hints. A hint in this case is a partial credentials containing only username, but no password. For retrieving hints you can use the method
Of course you can also delete credentials. Deleting credentials can be achieved with the method
The repository of RxSmartLock contains a sample app of using the library. Feel free to explore it and play more with SmartLock feature.
RxSmartLock is available on Maven central. To add it to your project you have to add the following dependency:
Use the class
RxGoogleSmartLockManager as a main entry point to start working with SmartLock API. It is a singleton (object in Kotlin)
Finally let’s talk about testing:
SmartLockManager is an interface and in production you should use RxGoogleSmartLockManager which is the default implementation provided by us.
In your espresso tests, however, you might want to use the EmptySmartLockManager implementation. It is a dummy implementation of the
SmartLockManager interface and all methods are doing nothing.
EmptySmartLockManager especially useful in espresso tests, since it doesn’t interact with the real SmartLock API and no SmartLock dialog is shown. This was a major source of flaky espresso tests for us.