Home  /  android  /  common

Absent live data

Barcode scanner using Google Vision

Camera2 implementation in an extendable Fragment

If you’re going to add a custom camera to your app, use these snippets to do it right. This recipe uses the Camera2 APIs, and hides all the weird code required for setting up a viewfinder and taking pictures.

Read more…

Custom TestRunner

Double trigger livedata transformation

Encrypted shared prefs


Get the SHA of a keystore

Gets the MD5, SHA1 and SHA256 of a keystore. You’ll need this for many signin solutions, such as Google SignIn, Facebook, Twitter, etc.

Read more…

Getting the user's location

HtmlCompat for Android Nougat and up

Lock an app using the phone's default lock screen

The snippets below can lock access to the app whenever the user leaves the app and comes back, with an optional timeout.

Read more…

Monitor permission status

Use LiveData to determine the status of any permission (in the sample code below: the location permission). If the user grants the permission at any point, then we will get notified.

Read more…

Open settings activity

Start the App Settings Activity so that the user can change settings related to the application, such as permissions.

Read more…


A very complete recipe that implements a RecyclerView that pulls in paginated data, using Retrofit, LiveData. It includes example models, adapter, viewholders, and a viewholder for displaying the network state in case of an error.

Read more…

Room type converters

Showing notifications

Simple date formatting cheatsheet

Soft keyboard event listener

Take a picture using the default camera

Turn timestamps into "time ago" strings

This recipe creates a “time ago” string from any timestamp, often used to display how long ago a comment was posted or a notification was received. We’re creating an extension method, so any Long timestamp can be converted like so: 12313131.timeAgo(arr) where arr is a list of labels. This list can be retrieved from a string-array in the strings.xml to make it localizable.

Read more…

Using the clipboard

Vibration and haptic feedback