phonegap中文文档_PhoneGap中文Api帮助文档

The connection object, exposed via navigator.connection, provides information about the device's cellular and wifi connection.

Android

app/res/xml/config.xml

app/AndroidManifest.xml

BlackBerry WebWorks

www/plugins.xml

iOS

config.xml

Windows Phone

Properties/WPAppManifest.xml

Tizen

config.xml

Checks the currently active network connection.

This property offers a fast way to determine the device's network

connection state, and type of connection.

iOS

Android

BlackBerry WebWorks (OS 5.0 and higher)

Tizen

Windows Phone 7 and 8

Windows 8

function checkConnection() {

var networkState = navigator.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.CELL] = 'Cell generic connection';

states[Connection.NONE] = 'No network connection';

alert('Connection type: ' + states[networkState]);

}

checkConnection();

navigator.connection.type Example

// Wait for device API libraries to load

//

document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available

//

function onDeviceReady() {

checkConnection();

}

function checkConnection() {

var networkState = navigator.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.CELL] = 'Cell generic connection';

states[Connection.NONE] = 'No network connection';

alert('Connection type: ' + states[networkState]);

}

A dialog box will report the network state.

Until Cordova 2.3.0, the navigator.network.connection, after which it was changed to

navigator.connection to match the W3C specification. It's still

available at its original location, but is deprecated and will

eventually be removed.

iOS cannot detect the type of cellular network connection.

When running in the emulator, always detects

Windows Phone cannot detect the type of cellular network connection.

Tizen can only detect a WiFi or cellular connection.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值