这篇博文介绍了html5+在webApp开发中经常使用的功能模块
获取wifi信息
获取wifi的IP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15function getOnuIp() {
if(mui.os.android) {
var Context = plus.android.importClass("android.content.Context");
var WifiManager = plus.android.importClass("android.net.wifi.WifiManager");
var WifiInfo = plus.android.importClass("android.net.wifi.WifiInfo");
var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE);
var wifiInfo = wifiManager.getConnectionInfo();
var ipAddress = wifiInfo.getIpAddress();
if(ipAddress == 0) return "未连接wifi";
return((ipAddress & 0xff) + "." + (ipAddress >> 8 & 0xff) + "." + (ipAddress >> 16 & 0xff) + "." + (ipAddress >> 24 & 0xff));
} else if(mui.os.ios) {
mui.toast("ios暂未获");
}
}获取wifi的网关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21function getOnuIp() {
if(mui.os.android) {
var Context = plus.android.importClass("android.content.Context");
var WifiManager = plus.android.importClass("android.net.wifi.WifiManager");
var WifiInfo = plus.android.importClass("android.net.wifi.WifiInfo");
var DhcpInfo=plus.android.importClass("android.net.DhcpInfo");
var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE);
var dhcpInfo = wifiManager.getDhcpInfo()
var begin=dhcpInfo.toString().indexOf("gateway");
var end=dhcpInfo.toString().indexOf("netmask");
var ipAddress = dhcpInfo.toString().substring(begin+7,end).trim();
if(ipAddress == 0) return "未连接wifi";
return ipAddress;
// return((ipAddress & 0xff) + "." + (ipAddress >> 8 & 0xff) + "." + (ipAddress >> 16 & 0xff) + "." + (ipAddress >> 24 & 0xff));
} else if(mui.os.ios) {
var WifiManager = plus.ios.importClass("WifiManager");
var wifiManager = new WifiManager();
var gateWay = wifiManager.defaultGateWay();
return gateWay;
}
}
软键盘
强制打开全键盘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44//弹出软键盘,搜索框获得焦点
var nativeWebview, imm, InputMethodManager;
var initNativeObjects = function() {
if(mui.os.android) {
var main = plus.android.runtimeMainActivity();
var Context = plus.android.importClass("android.content.Context");
InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
} else {
nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
}
};
var showSoftInput = function() {
if(mui.os.android) {
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
} else {
nativeWebview.plusCallMethod({
"setKeyboardDisplayRequiresUserAction": false
});
}
setTimeout(function() {
//此处可写具体逻辑设置获取焦点的input
var inputElem = document.querySelector('input');
inputElem.focus();
}, 200);
};
var showSoftInput2 = function() {
var nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
if(mui.os.android) {
//强制当前webview获得焦点
plus.android.importClass(nativeWebview);
nativeWebview.requestFocus();
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
} else {
nativeWebview.plusCallMethod({
"setKeyboardDisplayRequiresUserAction": false
});
}
setTimeout(function() {
//此处可写具体逻辑设置获取焦点的input
var inputElem = document.querySelector('input');
inputElem.select();
}, 200);
};关闭软键盘
1
document.activeElement.blur(); //隐藏软键盘
两次点击退出
1 | //首页返回键处理 |
注销关闭其他窗口
1 | /*监听注销按钮*/ |