All snippets tagged with android

Page 5 of 7

Repeating a bitmap pattern

Connectivity live data

Check if current connection is WiFi

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…

Take a picture using the default camera

Soft keyboard event listener

Room type converters

Open settings activity

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

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…

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…

Getting the user's location


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…

HtmlCompat for Android Nougat and up

Encrypted shared prefs

Double trigger livedata transformation