Skip to content

Instantly share code, notes, and snippets.


This gist expands on the initial functionality of the gist. This is a more flexible version that exposes the functionality to select a device and then use that serial number in one or more adb commands.

Companion blog post for usage is 🔗 here.

View crashlytics_disable_file_upload.kts
getByName("debug") {
configure<CrashlyticsExtension> {
mappingFileUploadEnabled = false
View shortcuts.xml
<androidx.preference.Preference app:title="Bag Reminders">
<intent android:action="android.intent.action.VIEW"
android:targetPackage="com.woolworths.debug" />
View choose_theme.kt
fun showThemeSwitcher(activity: Activity, prefs: SharedPreferences) {
val builder = AlertDialog.Builder(activity)
val names = mutableListOf<String>()
var selectedTheme = getSelectedTheme(activity, prefs).ordinal
builder.setTitle("Choose theme to apply")
builder.setSingleChoiceItems(SwitchableThemes.values().mapTo(names) {
}.toTypedArray(), selectedTheme) { _, which ->
selectedTheme = which
}.setPositiveButton(R.string.ok) { dialog, which ->
View debug_toast.kt
fun Context.showDebugToast(message: String, settingsInteractor: SettingsInteractor) {
if (settingsInteractor.shouldShowDebugToasts()) {
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
View save_logcat.kt
fun saveLogs() {
val debugDirectory = getStorageDirectory(this)
val logFile = File(debugDirectory, "logcat" + System.currentTimeMillis() + ".txt")
try {
var process = Runtime.getRuntime().exec("logcat -c")
process = Runtime.getRuntime().exec("logcat -f $logFile")
} catch (e: IOException) {
zmdominguez /
Last active July 1, 2019 08:42
Inspecting and Resetting preferences

This is a helper function for an app's debug or development drawer and is designed to be pasted into an Activity. It retrieves all files from shared_prefs and allows the user to choose which files to inspect or reset to default values. It is extremely helpful when testing one-shot scenarios such as for hints or onboarding, etc.

It assumes that the files are named in a consistent and predictable way -- more specifically by prefixing them with the application ID as mentioned here. For maximum consistency, this assumes that files are named similar to how the system names the default SharedPreferences file (MY.PACKAGE.ID_my_preferences).

All the application-specific preferences files are displayed in an AlertDialog. For readability, the application ID is stripped out.

View features_enum.kt
enum class Feature(val remoteConfigKey: String, val defaultValue: Boolean) {
FEATURE_1("feature_1_key", false),
FEATURE_2("feature_2_key", true),
FEATURE_3("feature_3_key", true)
View app_shortcut_multiple_intent.xml
<shortcut …>
<extra android:name="target_tab" android:value="settings" />