h5+ 开发app 系统、版本检测

设备信息

plus.device.model  //设备型号
plus.device.vendor  //设备的生产厂商
plus.device.imei  // IMEI 设备的国际移动设备身份码
plus.device.uuid  // UUID 设备的唯一标识
// IMSI 设备的国际移动用户识别码
var str = '';
for ( i=0; i<plus.device.imsi.length; i++ ) {
     str += plus.device.imsi[i];
}
plus.screen.resolutionWidth*plus.screen.scale + " x " + plus.screen.resolutionHeight*plus.screen.scale ; 
//屏幕实际分辨率
plus.screen.dpiX + " x " + plus.screen.dpiY; //DPI每英寸像素数

plus.screen.resolutionWidth // 设备宽度
plus.screen.resolutionHeight // 设备高度
plus.screen.scale   // 逻辑分辨率与实际分辨率的比例

通过js获取屏幕宽度

document.documentElement.clientWidth
// 在华为手机上测试比实际值多了一像素

封装方法返回设备对象信息

// 封装获取方法
var bonly = {};
bonly.getDeviceInfo = function(callback) {
	var deviceInfo = {};
	deviceInfo.model = plus.device.model;
	deviceInfo.vendor = plus.device.vendor;
	deviceInfo.imei = plus.device.imei;
	deviceInfo.uuid = plus.device.uuid;
	var str = '';
	for(i = 0; i < plus.device.imsi.length; i++) {
		str += plus.device.imsi[i];
	}
	deviceInfo.imsi = str;
	 // 逻辑分辨率与实际分辨率的比例
	deviceInfo.scale = plus.screen.scale;
	deviceInfo.resolution = plus.screen.resolutionWidth * plus.screen.scale + " x " + plus.screen.resolutionHeight * plus.screen.scale;
	deviceInfo.pixel = plus.screen.dpiX + " x " + plus.screen.dpiY;
	callback(deviceInfo);
}

// 调用
bonly.getDeviceInfo(function(info){
	console.log(JSON.stringify(info));
	// 输出 {"model":"T1-A21w","vendor":"HUAWEI","imei":"66Y6R15B02001892","uuid":"66Y6R15B02001892","imsi":"","scale":1,"resolution":"800 x 1232","pixel":"160 x 160.156998"}
}) 

手机信息

plus.os.name //名称
plus.os.version //版本
plus.os.language //语言
plus.os.vendor //厂商
//网络类型
var types = {};
types[plus.networkinfo.CONNECTION_UNKNOW] = "未知";
types[plus.networkinfo.CONNECTION_NONE] = "未连接网络";
types[plus.networkinfo.CONNECTION_ETHERNET] = "有线网络";
types[plus.networkinfo.CONNECTION_WIFI] = "WiFi网络";
types[plus.networkinfo.CONNECTION_CELL2G] = "2G蜂窝网络";
types[plus.networkinfo.CONNECTION_CELL3G] = "3G蜂窝网络";
types[plus.networkinfo.CONNECTION_CELL4G] = "4G蜂窝网络";
var network = types[plus.networkinfo.getCurrentType()];

封装方法返回手机信息对象

var bonly = {};
// 获取手机信息
bonly.getPhoneInfo=function(callback){
	var json = {};
	json.name = plus.os.name;
	json.version = plus.os.version;
	json.language = plus.os.language;
	json.vendor = plus.os.vendor;
	var types = {};
	types[plus.networkinfo.CONNECTION_UNKNOW] = "未知";
	types[plus.networkinfo.CONNECTION_NONE] = "未连接网络";
	types[plus.networkinfo.CONNECTION_ETHERNET] = "有线网络";
	types[plus.networkinfo.CONNECTION_WIFI] = "WiFi网络";
	types[plus.networkinfo.CONNECTION_CELL2G] = "2G蜂窝网络";
	types[plus.networkinfo.CONNECTION_CELL3G] = "3G蜂窝网络";
	types[plus.networkinfo.CONNECTION_CELL4G] = "4G蜂窝网络";
	json.network = types[plus.networkinfo.getCurrentType()];	
	callback(json);
}

// 调用
bonly.getPhoneInfo(function(info) {
	console.log(JSON.stringify(info));
	// {"name":"Android","version":"8.0.0","language":"zh_CN","vendor":"Google","network":"WiFi网络"}
})

mui判断是安卓还是ios

// 安卓
if( mui.os.android ) 为真

// ios
if( mui.os.ios ) 为真

版本检测

// 安卓机弹出安卓版本,ios弹出ios版本

mui.os.version

官方文档 mui.os.*

文章参考匠心博客

东翌编程