Device detection if is android?

Nakib picture Nakib · Aug 18, 2015 · Viewed 15.3k times · Source

I have an meteor app that is deployed for both ios and android device and i want certain code to run on only ios device and not on android. I know that I can detect device using navigator.userAgent but this will only work if i have my app running on browser.

//This works if its a browser

navigator.userAgent.toLowerCase().indexOf("android") > -1;

But is there any possible way to detect device if i have created bundle for android using meteor cordova plugin so it works like a native app.

Answer

Roee picture Roee · May 9, 2018

No reason for plugins, just use window.

window.cordova.platformId

You can also get the version of the os.

Full output:

window.cordova.platformId

"android"

window.cordova.platformVersion

"7.0.0"