Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Detecting IOS/Android/WindowsPhone Device

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Detecting IOS/Android/WindowsPhone Device

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Detecting IOS/Android/WindowsPhone Device

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)

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Detecting IOS/Android/WindowsPhone Device

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

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Detecting IOS/Android/WindowsPhone Device

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Detecting IOS/Android/WindowsPhone Device

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

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Detecting IOS/Android/WindowsPhone Device

that works, thanks again!

Alex GG
Posts: 0
Joined: Thu Nov 14, 2013 11:11 pm

Detecting IOS/Android/WindowsPhone Device

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Detecting IOS/Android/WindowsPhone Device

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

Return to “Issues”