-
How to use 9-patch images for resizable backgrounds in Android
In Android, almost all views can have a background colour or image set. Whilst a colour can be any size / shape, as can a vector drawable, a bitmap drawable cannot. For example, trying to make a 100px wide & 100px tall image 500px wide and 50px tall would result in a blurry, and horribly distorted background.
-
Using Dyno to create a Discord command that displays a message and DMs a specified user
Dyno is an extremely powerful bot for Discord, with a staggering set of features, split into modules. One of the easiest to use is the “Custom Command” module, allowing actions to be taken in response to messages in chat. Setting up Dyno to a server you have “Manage server” permissions on is very straightforward, just click “Add to server” on Dyno.gg, then follow the instructions.
-
How to disable your app's preview image in Android's task / app switcher
The easiest way to disable your app’s preview when your app is shown in task switcher is FLAG_SECURE.
-
How to programmatically change your Android app icon and name
In Android, your app’s icon is a crucial part of your project. It’s what grabs the user’s attention first, identifies your app amongst the sea of competitors, and is the most important piece of visual branding. However, usually this icon is defined in your manifest, then never changes except through update.
-
Resolving crash "IllegalArgumentException x is unknown to this NavController"
Google’s AndroidX navigation libraries are undoubtedly extremely useful, however they have a few quirks. For example, the following stack trace recently started showing up in my Crashlytics crash logs:
-
How to check if a Sony Android device has "Stamina mode" enabled
Whilst detecting power saving mode (at least on Lollipop+) is very easy, some manufacturers implement their own battery saving systems. One of the least standards-conforming of these is Sony’s Stamina Mode. Luckily this is easily detected, albeit in an unofficial way.
-
How to fix NoClassDefFoundError "Failed resolution of: Lorg/apache/http/ProtocolVersion"
I recently updated an older app, and changed the target API from 27 to 28, as recommended. This app is using an older (15.x.x) version of the Google Maps library. Upon trying to actually use Google Maps, I received the following crash:
-
Quickly setting up commit verification / signing with GitHub, GitKraken, and GPG
Whilst most developers use hosted git repositories on a service like GitHub, many forget that almost none of these commits are verified. If you own a repository, you can “fake” a commit from literally any user if you know their email. If that email matches a GitHub account, their avatar will be displayed next to their name! One famous example is a fake commit by Linus Torvalds.
-
Automatically adding build time to your Android app
When releasing an Android app, it can be useful to show your users the current version name (BuildConfig.VERSION_NAME) or code (BuildConfig.VERSION_CODE). Another nice feature is showing when this version of the app was built, to reassure users that features / bug fixes are being released frequently.
-
Creating a preference utility to safely handle Android SharedPreferences
Saving and retrieving shared preference values in Android is relatively straightforward, but doing it safely can be problematic. For example, you may set a default value, then accidentally use a different default value when retrieving!