獲取手機設(shè)備的相關(guān)信息炉爆,如IMEI堕虹、IMSI、型號赴捞、廠商等逼裆。通過plus.device獲取設(shè)備信息管理對象。
獲取當前運行環(huán)境信息赦政、與其它程序進行通訊等胜宇。通過plus.runtime可獲取運行環(huán)境管理對象恢着。
直接上demo
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link href="../../css/mui.min.css" rel="stylesheet" />
<script src="../../js/mui.js"></script>
<script src="../../js/vue.js"></script>
<style>
body{max-width: 750px; min-width: 320px; margin: 0 auto; background-color: #F5F5F5;overflow-x: hidden;
font-family: -apple-system,Helvetica,sans-serif;}
div{font-size: .26rem; color: #474747;line-height: 2;}
span{font-size: .28rem; color: #D1021F;}
</style>
<script>
(function(doc, win) {
var w = document.documentElement.clientWidth;
if (w > 750) {
w = 750
} else if (w < 320) {
w = 320
}
var f = w / 750 * 100 + "px";
document.documentElement.style.fontSize = f;
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
var clientWidth = docEl.clientWidth > 750 ? 750 : docEl.clientWidth;
if (clientWidth > 750) {
clientWidth = 750
} else if (clientWidth < 320) {
clientWidth = 320
}
if (!clientWidth) return;
docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
</script>
</head>
<body>
<header class="mui-bar mui-bar-nav">
<h1 class="mui-title">我的手機信息</h1>
</header>
<div id="content" class="mui-content mui-content-padded">
<div class="mui-text-left" v-for="item in list">
{{item.title}}
<span>
{{item.value}}
</span>
</div>
</div>
<script type="text/javascript">
var spans = document.getElementsByTagName('span');
var VM = new Vue({
el: ".mui-content",
data: {
list:[]
},
})
mui.plusReady(function() {
//獲取系統(tǒng)名稱
var name = plus.os.name;
VM.list.push({
"title": "系統(tǒng)名稱",
"value": name
})
//獲取系統(tǒng)版本
var version = plus.os.version;
VM.list.push({
"title": "系統(tǒng)版本",
"value": version
})
//設(shè)備型號
VM.list.push({
"title": "設(shè)備型號",
"value": plus.device.model
})
//獲取生產(chǎn)廠商
var vendor2 = plus.device.vendor
VM.list.push({
"title": "生產(chǎn)廠商",
"value": vendor2
})
//獲取系統(tǒng)供應(yīng)商
var vendor = plus.os.vendor
VM.list.push({
"title": "系統(tǒng)供應(yīng)商",
"value": vendor
})
//獲取系統(tǒng)語言信息
var language = plus.os.language;
VM.list.push({
"title": "系統(tǒng)語言信息",
"value": language
})
var types = {}; //網(wǎng)絡(luò)類型
types[plus.networkinfo.CONNECTION_UNKNOW] = "未知";
types[plus.networkinfo.CONNECTION_NONE] = "未連接網(wǎng)絡(luò)";
types[plus.networkinfo.CONNECTION_ETHERNET] = "有線網(wǎng)絡(luò)";
types[plus.networkinfo.CONNECTION_WIFI] = "WiFi網(wǎng)絡(luò)";
types[plus.networkinfo.CONNECTION_CELL2G] = "2G蜂窩網(wǎng)絡(luò)";
types[plus.networkinfo.CONNECTION_CELL3G] = "3G蜂窩網(wǎng)絡(luò)";
types[plus.networkinfo.CONNECTION_CELL4G] = "4G蜂窩網(wǎng)絡(luò)";
var network = types[plus.networkinfo.getCurrentType()];
VM.list.push({
"title": "網(wǎng)絡(luò)類型",
"value": network
})
//獲取設(shè)備的唯一標示
plus.device.getInfo({
success: function(e) {
VM.list.push({
"title": "國際移動設(shè)備身份碼imei",
"value": e.imei
})
VM.list.push({
"title": "國際移動用戶識別碼imsi",
"value": e.imsi
})
VM.list.push({
"title": "設(shè)備的唯一標識",
"value": e.uuid
})
},
fail: function(e) {
console.log('getDeviceInfo failed: ' + JSON.stringify(e));
}
});
//獲取APP版本信息
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
var ver = inf.version;
VM.list.push({
"title": "APP名稱",
"value": inf.name
})
VM.list.push({
"title": "APP版本信息",
"value": "版本:"+inf.version+"掰派;版本號:"+inf.versionCode
})
console.log(JSON.stringify(inf))
})
});
//獲取IP地址信息
function addScriptTag(src) {
var script = document.createElement('script');
script.setAttribute("type", "text/javascript");
script.src = src;
document.body.appendChild(script);
}
function foo(data) {
var json = data.data[0];
VM.list.push({
"title": "位置",
"value": json.location
})
VM.list.push({
"title": "IP地址",
"value": json.origip
})
console.log("IPInfo:"+ JSON.stringify(json));
};
window.onload = function() {
addScriptTag(
'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=ip&co=&resource_id=6006&t=1562124098965&ie=utf8&oe=gbk&cb=foo&format=json&tn=baidu'
);
}
</script>
</body>
</html>
注意:
獲取IP地址和plus.device.getInfo都是異步的,所以在使用的時候要注意時機
效果圖:
Android和IOS獲取imei盏求、imsi、uuid時須知:
imei: (String 類型 )設(shè)備的國際移動設(shè)備身份碼
如果設(shè)備不支持或無法獲纫诿摺(如用戶未授權(quán))則返回空字符串。 如果設(shè)備存在多個身份碼纳像,則以“,”字符分割拼接,如“862470039452950,862470039452943”竟趾。
平臺支持
Android - ALL (支持): 需要用戶授權(quán)才能獲取,如果用戶拒絕獲取設(shè)備信息則返回空字符串岔帽。
iOS - ALL (不支持): 無法獲取設(shè)備身份碼玫鸟,返回空字符串犀勒。
imsi: (Array[ String ] 類型 )設(shè)備的國際移動用戶識別碼
字符串數(shù)組類型,獲取設(shè)備上插入SIM的國際移動設(shè)備身份碼贾费。 如果設(shè)備支持多卡模式則返回所有SIM身份碼钦购。 如果設(shè)備不支持或沒有插入SIM卡則返回空數(shù)組褂萧。
平臺支持
Android - ALL (支持): 如果無法獲取國際移動用戶標識(如用戶未授權(quán))則返回空數(shù)組押桃。
iOS - ALL (不支持): 無法獲取設(shè)備移動用戶識別碼导犹,返回空數(shù)組羡忘。
uuid: (String 類型 )設(shè)備標識
設(shè)備的唯一標識號。
平臺支持
Android - ALL (支持): 與設(shè)備的imei號一致磕昼。 注意:如果無法獲取設(shè)備imei則使用設(shè)備wifi的mac地址,如果無法獲取設(shè)備mac地址則隨機生成設(shè)備標識號(不同App在同一臺設(shè)備上獲取的值一致)掰烟。
iOS - ALL (不支持): 根據(jù)包名隨機生成的設(shè)備標識號。 注意:設(shè)備重置(刷機)后會重新生成
其他的屬性和方法纫骑,參考html5plus官網(wǎng):
http://www.html5plus.org/doc/zh_cn/device.html
歡迎轉(zhuǎn)載蝎亚,但是請注明出處