zoukankan      html  css  js  c++  java
  • PhoneGap Connection

    Connection
      Connection对象提供对设备的蜂窝及WiFi连接信息的访问。
    通过navigator.network接口访问该对象。
    属性:
    常量:
    connection.type 
     
    检查正在使用的活动网络连接。
    说明:
    该属性是确定设备网络连接状态和连接类型的快速方法。
    支持的平台:
    • iOS
    • Android
    • BlackBerry WebWorks (OS 5.0或更高版本)
    • Windows Phone 7 ( Mango )
    简单的范例:
    复制
    function checkConnection() {
    	var networkState = navigator.network.connection.type;
    	
    	var states = {};
    	states[Connection.UNKNOWN]  = 'Unknown connection';
    	states[Connection.ETHERNET] = 'Ethernet connection';
    	states[Connection.WIFI]     = 'WiFi connection';
    	states[Connection.CELL_2G]  = 'Cell 2G connection';
    	states[Connection.CELL_3G]  = 'Cell 3G connection';
    	states[Connection.CELL_4G]  = 'Cell 4G connection';
    	states[Connection.NONE]     = 'No network connection';
    	
    	alert('Connection type: ' + states[networkState]);
    }
    	
    checkConnection();
    完整的范例:
    复制
    <!DOCTYPE html>
    <html>
    <head>
    <title>navigator.network.connection.type Example</title> 
    
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script> 	
    <script type="text/javascript" charset="utf-8">  
    
    	// 等待加载PhoneGap
    	document.addEventListener(deviceready, onDeviceReady, false);  
    
    	// PhoneGap加载完毕,可以安全调用PhoneGap方法
    	function onDeviceReady() { 
    		checkConnection(); 
    	}  
    
    	function checkConnection() { 
    		var networkState = navigator.network.connection.type; 		 
    
    		var states = {}; 
    		states[Connection.UNKNOWN]  = 'Unknown connection'; 
    		states[Connection.ETHERNET] = 'Ethernet connection'; 
    		states[Connection.WIFI]     = 'WiFi connection'; 
    		states[Connection.CELL_2G]  = 'Cell 2G connection'; 
    		states[Connection.CELL_3G]  = 'Cell 3G connection'; 
    		states[Connection.CELL_4G]  = 'Cell 4G connection'; 
    		states[Connection.NONE]     = 'No network connection'; 
    
    		alert('Connection type: ' + states[networkState]); 
    }
    
    </script>
    </head>
    <body>
    	<p>A dialog box will report the network state.</p>
    </body>
    </html>
  • 相关阅读:
    D3制作力导向图
    page分页问题,根据页码获取对应页面的数据,接口调用
    python列表生成式、键盘输入及类型转换、字符串翻转、字母大小写、数组广播、循环语句等基础问题
    python中将已有链接的视频进行下载
    机器学习1
    python 排序算法
    LintCode 练习题
    python 装饰器的使用
    hive 学习笔记
    hive 操作
  • 原文地址:https://www.cnblogs.com/mingforyou/p/2944162.html
Copyright © 2011-2022 走看看