标签:
1 function plusReady(){ 2 3 var types = {}; 4 5 types[plus.networkinfo.CONNECTION_UNKNOW] = "Unknown connection"; 6 7 types[plus.networkinfo.CONNECTION_NONE] = "None connection"; 8 9 types[plus.networkinfo.CONNECTION_ETHERNET] = "Ethernet connection"; 10 11 types[plus.networkinfo.CONNECTION_WIFI] = "WiFi connection"; 12 13 types[plus.networkinfo.CONNECTION_CELL2G] = "Cellular 2G connection"; 14 15 types[plus.networkinfo.CONNECTION_CELL3G] = "Cellular 3G connection"; 16 17 types[plus.networkinfo.CONNECTION_CELL4G] = "Cellular 4G connection"; 18 19 alert( "Network: " + types[plus.networkinfo.getCurrentType()] ); 20 21 } 22 23 if(window.plus){ 24 25 plusReady(); 26 27 }else{ 28 29 document.addEventListener("plusready",plusReady,false); 30 31 }
1 mui.plusReady(function() { 2 document.addEventListener("netchange",onNetChange,false); 3 function onNetChange(){ 4 //获取当前网络类型 5 var nt = plus.networkinfo.getCurrentType(); 6 switch(nt){ 7 case plus.networkinfo.CONNECTION_ETHERNET: 8 case plus.networkinfo.CONNECTION_WIFI: 9 mui.toast("当前网络为WiFi"); 10 break; 11 case plus.networkinfo.CONNECTION_CELL2G: 12 case plus.networkinfo.CONNECTION_CELL3G: 13 case plus.networkinfo.CONNECTION_CELL4G: 14 mui.toast("当前网络非WiFi"); 15 break; 16 default: 17 mui.toast("当前没有网络"); 18 break; 19 } 20 }
标签:
原文地址:http://www.cnblogs.com/atomicdog/p/mui_net.html