Home Classroom Android Development Agile development of Android apps – Process Tip #1: Detect the emulator

Agile development of Android apps – Process Tip #1: Detect the emulator

Developing many Android apps I found that a lot of methods are non-application-specific which means I can extract them into a Utils class which I can then share among various projects. One of my most useful methods is Utils.isEmulator(). This allows me to write into the app behavior which will be optimized for development in case the app is running inside an emulator supplied by an SDK and optimized for end-users in case it’s running on an actual device.

Here’s a use case example. Let’s say you’re building an alarm clock for Android and you want to test the snoozing feature. Let’s say the snooze period has a minimum length of 5 minutes. It will be a waste of time for you to wait 5 minutes every time you hit snooze when you’re actually testing this on the emulator, so why not set it to 1 in this case?

final int minutes = Utils.isEmulator() ? 1 : 5;

While developing the application yourself you’ll find many such use cases. At the moment there is no full proof, recommended way of checking whether you’re running in an emulator or not but the following implementation never failed me:

private static final boolean IS_EMULATOR = android.os.Build.MODEL.endsWith("sdk");

public static boolean isEmulator() {

Packaging both behaviors in the same ‘shipment’ (.apk file) is also convenient because it allows you to enable a debug/development mode when you’re helping customers or when you’re just testing functionality on real devices (e.g. simply by forcing IS_EMULATOR to be true in the implementation above in case some button is pressed). In my next process tip, I’ll share another use case for isEmulator() which isn’t application specific and which you can use in every single app you build from now on.




Leave a Reply