Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device detection if is android?

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.

like image 836
Nakib Avatar asked Aug 18 '15 20:08

Nakib


People also ask

How do you identify a mobile phone?

The easiest way to check your phone's model name and number is to use the phone itself. Go to the Settings or Options menu, scroll to the bottom of the list, and check 'About phone', 'About device' or similar. The device name and model number should be listed.

What is device detection?

Device Detection is the process of capturing accurate real-time intelligence about the devices being used to access online information, including web and native apps. This Device Intelligence is used to identify where online content is performing best on any device, regardless of screen size.

How can I tell if a device is mobile JavaScript?

To detect if the user is using a mobile device in JavaScript, we can use the userAgent property. This property is part of the navigator object and sent by the browser in HTTP headers. It contains information about the name, version, and platform of the browser.


2 Answers

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"

like image 148
Roee Avatar answered Oct 09 '22 21:10

Roee


As Nijil Nair suggested use the Cordova Device Plugin . If you need help adding the plugin see Meteor Cordova . Once the plugin is properly installed you can use var devicePlatform = device.platform; which will return one of the following based on the device:

  • "Android"
  • "BlackBerry"
  • "iOS"
  • "WinCE"
like image 43
Nate Avatar answered Oct 09 '22 22:10

Nate