Play sound on Android

Motivation When writing app you sometimes want to play some sounds e.g. for notifications. In Android this can be accomplished by using the SoundPool class. Resource files Resource files e.g. your wav shall be placed under app\src\main\res\raw Code snippet This is a working example for playing short sound files. If you want to make a…

Android: Fix Unauthorized Devices on macOS

Disconnect USB connection between Mac/MacBook and Android device On the device: Revoke USB debugging authorization in Settings -> Developer Options cd /Users/<user_name>/Library/Android/sdk/platform-tools ./adb kill-server cd ~/.android/ rm -rf adbkey  Reconnect device Re-authorize computer to device cd /Users/<user_name>/Library/Android/sdk/platform-tools check with ./adb devices that device is authorized

Log4j2 for Kotlin

Motivation Logging is a common good practice in software engineering. It enables you to monitor applications in production to gather information about crashes and other malfunctions for further analysis. It is the “little brother” of debugging and often a precursor for setting up test cases which can lead to reproducing the bugs on the developers…

Kotlin Scripts with Gradle

If you are using Gradle and you want to run a Kotlin script you have to add the following to your build.gradle file dependencies { implementation “org.jetbrains.kotlin:kotlin-stdlib” implementation ‘org.jetbrains.kotlin:kotlin-script-runtime:1.4.32’ }

Argparse

Primer: Arguments vs Parameters I’m sometimes confused. Is it an argument or a parameter? So here it goes: A parameter is a variable in a function definition. When a function is called, the arguments are the data you pass into the function’s parameters. The same goes for a program: A program has parameters, you call…

Android Asynchronous Http Client

Motivation In Android it is highly inadvisable to do heavy lifting in the UI thread. When you even try to do some networking stuff like fetching images from a web server you might get an android.os.NetworkOnMainThreadException I’ve also written about it here To work around this issue you can use a third party library like…