Appcelerator Blog

The Leading Resource for All Things Mobile

How to detect and run code specific to Genymotion Emulators

0 Flares 0 Flares ×

When you are running test you might need to differentiate for specific environments. For example, if you haven’t patched your Genymotion emulators to include the missing Google Apps you would need to skip any tests that use Google Play Services like for ti.map.

To detect which emulator you are running your code in, you can use Ti.Platform.manufacturer, which returns unknown on Android Virtual Devices, but Genymotion on Genymotion emulators.

Example Code

var isGenymotion = (Ti.Platform.name === 'android' && Ti.Platform.manufacturer === 'Genymotion');

var win = Ti.UI.createWindow();

win.add(Ti.UI.createLabel({
  text: 'You ' + (isGenymotion ? 'ARE' : 'ARE NOT') + ' using Genymotion.\n' +
        'The manufacturer is: ' + Ti.Platform.manufacturer
}));

win.open();
Genymotion

Reconsider using AVDs

Genymotion became a popular alternative for the infamous slow AVDs. However, you might want to reconsider. Most of them include Google APIs, the performance has improved a lot recently and Android Studio makes it very easy to manage AVDs for tons of common devices:

AVD

And yes, these AVDs work fine with Titanium!

Code Strong! 🚀

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

3 Comments

  1. Buder

    Just a quicky then, is “all” I have to do install Android Studio, considering I now have a fully working environment? Also considering I am in production….

    • I’d never do any environment changes right before deadlines, but Android Studio will detect any existing Android SDK/NDK and just make managing it a lot easier.

  2. Thank you for this code. And I have checked and it is working.

Comments are closed.

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×