Posts

DI on Android (Kotlin) using an SPI

Image
Most developers are intimately familiar with what an API is. However, mention SPI, and many will look like a question mark. This blog entry explains what it is, discusses its merits/shortcomings and shows how it can serve as a simple Inversion of Control or Dependency Injection pattern on Android for providing testing mocks. So what is an SPI anyway? The term SPI is an abbreviation of Service Provider Interface , and it's nothing more than a contract (interface) with pluggable implementations (classes) discovered lazily at runtime. I have also seen this pattern referred to as Service Locator and Service Registry. It likely has a older history than I am aware of (you can use it if you have introspection and reflection available in your language) but I made its acquaintance with Java 1.3 which introduced these service providers as a way of facilitating loosely coupled modules. In Java 6 the pattern was embraced further by the addition of the SericeLoader class and whenever you...

Klaphatte til app brugere

Image
This entry is in Danish, as it contains quotes in this language which can not readily be translated without loss of meaning. Som app udvikler, må man være parat til at modtage en del flak (læs: beskydning med spredhagl fra folk der ikke ved bedre men brokker sig i øst og vest) og det er jo et relativ kendt fænomen der er skrevet om utallige steder som f.eks. her . Der sker bare noget med folk når de i relativ anonymitet, får lov til at udtale sig og bedømme på et meget spinkelt grundlag - pludselig er de eksperter og kunne lave det meget bedre selv. Eksempel på en klaphat I dag modtog jeg f.eks. følgende review fra Jesper (fulde navn og email bekendt af redaktionen) som jeg, som så ofte før, besvarer inde på Google Play. Jesper er jo et klassiske eksempel på en fejl-informeret bruger med en inkompatibel tlf. der ikke helt har brugt tid på at undersøge sagen nærmere. Fred være med det tænker jeg, NFC formater er også et tricky emne for alm. mennesker at forholde sig til. Me...

Android NFC radio control using instrumentation

Image
I have always worked a lot with NFC on Android. For this reason, I tend to favor real devices over emulators, since missing an NFC radio means there's no way to truly test the intricacies of radio communication. Unfortunately, one can not power cycle the NFC radio using any official API unless going through hoops and using rooted devices, so ensuring NFC radio power state during testing is an uphill battle. For instrumented test scenarios however, there is actually a way forward. UIAutomator to the rescue While not as elegant as using an API, we can launch the settings screen for NFC and manipulate it through the use of instrumentation. This is NOT possible using modern Espresso which limits you to the app under test, but thankfully the UIAutomator framework is still available. The accompanying UIAutomator Viewer tool (which has now moved to sdk/tools/bin/uiautomatorviewer) is a great asset in this regard as it helps us identify the widget we need to manipulate. What the...

BangBits Privacy Policy

Welcome to the BangBits Privacy Policy When you use apps and other software developer by BangBits, you trust us with your information. This Privacy Policy is meant to help you understand what data we collect, why we collect it, and what we do with it. It is important to understand, that BangBits operate both as an owner of given software and as a proxy for work developer by Customers. App's published by BangBits but taking part of a specific Customer solution are treated separately in the "Specific Products" section below. Information we collect and why we collect it We collect information to provide better customer experience. This may happen through various forms of remote logging using Google Analytics, Firebase Analytics or similar tool. At no time is personal data directly mappable to an identifiable user being collected. What can be collected is: Device identifiers (DeviceID, IMEI and handset identifiers) in order to black-list and/or white-list oth...

Best-practice Android logging

Image
A blog post about Android logging? Must be a slow news day you are probably already thinking, but hear me out on this one. This is a quick tour around my personal best-practices and you may likely not agree with all of them - if so, let me know in the comments. ;) Android Studio and LogCat On Android, logging has always been an integral part of the development experience, first through the standalone LogCat utility and since through the Android Studio integration. The build-in LogCat now even offers advanced filtering capabilities based on logging level, regular expressions for package names, logging tag and the actual log messages. However, all this power is really only useful if you play along nicely at the source level as well, or you will drown in log messages without really knowing how to specify what you want to see. This is a common problem as the Android OS and any libraries you may use will spit out an obscene amount of logging, especially at the verbose level. Use correct...

Rejsekort, NFC og smartphone kompatibilitet

Image
Det sker ikke så sjældent, at jeg får en mail på noget lignende følgende form: Min telefon har da NFC, hvorfor kan jeg så ikke downloade din app? Hvorfor sker ikke noget når jeg scanner kortet med din app? Jeg savner et sted hvor man kan se om hvilke telefoner der er kompatible med din app (Rejsekortscanner). Jeg kan finde nogle spredte informationer skrevet af dig. Nogle er 2 år gamle på din blog. Hvorfor vedligeholder du ikke bare en liste? Det er jo gode spørgsmål som jeg har svaret på rigtig mange gange de seneste par år. Det siger sig selv, at som udvikler er jeg naturligvis interesseret i, at gøre det så nemt og smertefrit for potentielle brugere som muligt - men Rejsekort og NFC er og bliver bare et kompliceret emne. Herunder har jeg forsøgt at bryde emnet ned i let-fordøjlige bidder. Hvad er NFC? NFC (Near Field Communication) udspringer af envejskommunikation RFID (Radio Frequency IDentification), og tillader kontaktløs tovejskommunikation med et smartcard. Det er ...

Android: Remove a dependency from a build variation

Image
Android's build variations (flavor and buildType) feature is an awesome way of maintaining several cuts from the same source code. I've used it both for white-label branding solutions and for Free vs. Pro versions. However, sometimes you have different dependencies between the versions where you will usually have to live with the fact, that all variations of your app gets the superset of dependencies. There are ways around this however, and I used it to shave over 400Kb off from a Free variation to a Pro variation. The problem Java is a static language, so you can't just go ahead and rely on late-bound linking and have Proguard slice and dice. It's unclear to me, whether the Android variations mechanism extends to Java source code, but I don't think it does. It's also unclear to me, whether an SPI approach could be used, letting the build class-path inject different implementations of some API for use at compile-time. What IS clear to me however, is that ...