Adds several features over the regular AndroidJUnitRunner:
Read more…All snippets tagged with android
Page 6 of 7Custom TestRunner
Using the clipboard
Copying and pasting from and to the system clipboard. Assuming text and/or html content.
Read more…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…Barcode scanner using Google Vision
The implementation of the Google Vision api is not that hard, but there are a few fixes you’ll need to make your app production ready. Most importantly: the default implementation does not support autofocus which makes it very hard to scan a barcode.
Read more…Absent live data
A LiveData class that has null
value.
Vibration and haptic feedback
For haptic feedback on button touches:
Read more…Showing notifications
Simple snippet for showing a notification. Tweak where needed.
Read more…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…FragmentActivity
This recipe is outdated! We’ll keep it for now, because it might be useful when maintaining old apps, but the
new prefered way is to use a FragmentContainerView
instead.
Okhttp 401 handler
Handle session expirations and 401 error codes. The following code will be activated if the API responds with a 401 (no authentication). If there’s a token that should be renewed, we first renew the token and if this is successful we try the original request again.
Read more…Using local JSON files as an API placeholder with Retrofit
With this snippet you can easily and quickly mock an API during developmentby placing JSON files in your res/raw/
folder. This comes in handy when the actual
API does not exist yet.
Pagination
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…Centralized error handling
Global error handling for REST requests.
Read more…Pair emulator Android Wear with real phone
To pair Wear running on an emulator with a physical phone, run this command targeting the emulator:
Read more…Install app as a system app on the emulator
Use the following commands to install your app as a system app on an emulator (or rooted device).
Read more…