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.

参与评论 您还未登录,请先 登录 后发表或查看评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:游动-白 设计师:我叫白小胖 返回首页

打赏作者

香侬科技

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值