Page 1 of 1

Detecting IOS/Android/WindowsPhone Device

Posted: Wed Nov 20, 2013 9:06 am
by Andy Parker

I'm trying to work out how I can detect what device my app is running on.

I've seen the post reply by Max that suggests using the Modernizr library but I still can't see how this will tell me the device type.

All I'm really interested in is finding out if the device type is Windows Phone, as I need to handle some code slightly differently from IOS and Android.

any help with this would be greatly appreciated, many thanks.

Andy.


Detecting IOS/Android/WindowsPhone Device

Posted: Wed Nov 20, 2013 10:32 am
by Maryna Brodina

Hello! We're working on it. I'll update.


Detecting IOS/Android/WindowsPhone Device

Posted: Wed Nov 20, 2013 10:53 am
by Maryna Brodina

On device ready event you can check device.platform - here is more information http://docs.phonegap.com/en/3.0.0/cor.... Another way is to check navigator.userAgent - https://developer.mozilla.org/en-US/d... (here is an example http://stackoverflow.com/a/11078197)


Detecting IOS/Android/WindowsPhone Device

Posted: Wed Nov 20, 2013 11:13 am
by Andy Parker

wow, this looks very useful, thank you.

I'll quickly add this to the app and report back.

once again, many thanks for your great support!

regards

Andy


Detecting IOS/Android/WindowsPhone Device

Posted: Wed Nov 20, 2013 1:31 pm
by Andy Parker

thanks for this.

I couldn't get the device.platform to work as "device" came back as not recognised (which was a shame).

I did however use the navigator.userAgent, this returns quite a long string, but after testing I have found that the word "Windows" does appear in the windows phone and doesn't appear in Android.

thanks again.


Detecting IOS/Android/WindowsPhone Device

Posted: Wed Nov 20, 2013 2:08 pm
by Maryna Brodina

device is accessible only after device ready event (if you test on device), but that should be enought if everything works with navigator.userAgent.


Detecting IOS/Android/WindowsPhone Device

Posted: Wed Nov 20, 2013 4:26 pm
by Andy Parker

that works, thanks again!


Detecting IOS/Android/WindowsPhone Device

Posted: Fri Jun 27, 2014 6:48 am
by Alex GG

Hi,
Im using this code to detect in which platform my app is open.

var plat=device.platform;

So in order to advice user to download my other apps, Im trying to use "plat" to redirect to AppStore or Google play, depending on the case.

So, what code should I use to open Appstore or Google play when the user tap on my "download X app"?

Regards


Detecting IOS/Android/WindowsPhone Device

Posted: Fri Jun 27, 2014 8:09 am
by Kateryna Grynko

Hi Alex,

Should be something like this:prevar url = "";
switch(plat){
case "Android": {
url = "link-to-your-app";
break;
}
case "IOS": {
url = "link-to-your-app";
break;
}
default:{
url = "link-to-your-app";
}
}
window.top.location = url;/pre