我正在用phonegap为三个不同的平台构建一个应用程序:安卓、iOS和黑莓。在这样做的同时,我必须检测设备类型,以便我可以在不同的平台上管理我的应用程序的高度和宽度,并针对不同的设备,如安卓手机、安卓平板电脑、iPhone、iPad和黑莓……
发布于 2012-06-18 14:59:52
如果你想在onDeviceReady之前得到设备类型,你可以这样得到。
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);发布于 2013-01-18 18:21:31
Phonegap中的新功能,也是最简单的功能,就是你可以使用device.platform:
// Depending on the device, a few examples are:
// - "Android"
// - "BlackBerry"
// - "iOS"
// - "webOS"
// - "WinCE"
// - "Tizen"
// - "browser"
var devicePlatform = device.platform;发布于 2015-06-12 18:16:08
cordova.platformId
// "android"https://stackoverflow.com/questions/11077853
复制相似问题