Monday, August 14, 2017

Sending an APK over bluetooth on Android

If you want to allow users to install an app offline, sending the APK file over bluetooth seems like a reasonable way forward. Regrettably, and without any real documentation the issue, some versions of Android block this. Perhaps it's anti-piracy.

APK receive over bluetooth was blocked on:
  • Nexus 4 (Android 5)
  • Nexus Galaxy (Android 4.3)
  • Yoga Tablet 2 Pro (Android 5)
APK receive over bluetooth works fine on:
  • Samsung SM-G313F (Android 4.4.2)
  • Wileyfox Swift (Android 7.1)
  • Moto E2 (Android 6)
The enable installation from unknown sources setting makes no difference. If receiving APK files are blocked on a device, no notification at all appears on the client device (thanks) when one is sent. The sender should receive a notification that sending failed. If sending an APK is blocked, the workaround is to send a zip file. There we are hoping that the phone has something capable of unzipping it. Most manufacturers install something for that, but stock Android has no file browser. You can get to a file manager through settings, storage, explore.

Wednesday, August 9, 2017

Android JUnit @BeforeClass flakiness for longer running routines

Using @BeforeClass in a JUnit test seems like a great way to make tests run more efficiently. Surely it's a natural place to put long-running setup routines!

Unfortunately, Android's test runner in Android Studio will, depending on how it feels, might run the next test, might skip the next test, might skip a couple more tests just for good measure, or it might just give up the tests entirely. Looking for an error message or a hint?

So instead of a nice elegant solution:
@BeforeClass
public static void someSlowSetupRoutine() {
    //run long running code
}
We must put the long running procedure in the test itself and use an if statement to avoid running it multiple times to speed things up:
@Test
public void someTest() {
    if(!ready){
        //run setup
    }
}