0

我目前正在开发 sencha touch 2 项目我想在不杀死应用程序实例的情况下显示一条消息“No Internet Access”我如何使用 sencha touch 2 或通过 phonegap 来实现这一点

4

1 回答 1

0

你可以检查到phonegap的连接如下

navigator.network.connection.type 示例

<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">

// Wait for Cordova to load
// 
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is loaded and it is now safe to make calls Cordova methods
//
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>

一个对话框将报告网络状态。

有关它的更多信息,请查看关于互联网连接的 PHONEGAP 文档

于 2012-08-13T05:55:00.053 回答