PhoneGap - 在 phonegap 中检测设备类型 [英] PhoneGap - Detect device type in phonegap

查看:24
本文介绍了PhoneGap - 在 phonegap 中检测设备类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 phonegap 中为三个不同的平台构建应用程序:Android、iOS 和 Blackberry.这样做时,我必须检测设备类型,以便我可以在不同平台和不同设备(如 Android 手机、Android 平板电脑、iPhone、iPad 和黑莓)上管理我的应用程序的高度和宽度...

I'm building an application in phonegap for the three different platforms: Android, iOS And Blackberry. While doing so, I have to detect the device type so that I can manage the height and width of my app on different platforms and for different devices like Android Phone, Android Tablet, iPhone, iPad and Blackberry...

推荐答案

如果你想在onDeviceReady之前获取设备类型,你可以这样获取.

if you want to get device type before onDeviceReady, you can get like this.

var deviceType = (navigator.userAgent.match(/iPad/i))  == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i))  == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";

alert(deviceType);

这篇关于PhoneGap - 在 phonegap 中检测设备类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆