überprüfung der internet-Verbindung des Geräts mit phonegap

Versucht die cordova-2.0.0 und mit diesem code für die überprüfung der internet-Verbindung

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

function onDeviceReady() {
    alert("ready");
    db = window.openDatabase("loginintro", "1.0", "loginintro", 1000000);
    db.transaction(populateDB, errorCB, successCB);
    checkConnection();
}
function checkConnection()
{   alert("connection");
    network = navigator.network.connection.type;
    alert("fdfd");
    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]);
}

aber immer Fehler auf dieser Linie

network = navigator.network.connection.type;

and error ist:

04-09 15:20:23.989: E/Web Console(13329): Uncaught TypeError: Cannot read property 'connection' of undefined at file:///android_asset/www/js/lib/helloworldjs/alldatabse.js:14
04-09 15:20:39.419: E/CordovaWebView(13329): CordovaWebView: TIMEOUT ERROR!
04-09 15:20:39.419: D/Cordova(13329): CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=file:///android_asset/www/index.html
Sie haben kleine Fehler im code. Es sollte alert('Connection type:' + states[Netzwerk])
guter Fang, das war der einzige Fehler, den jetzt meine Funktion ist in Ordnung, vielen DANK
seine onDeviceReady nicht onDeviceReady()

InformationsquelleAutor Erum | 2013-04-09

Schreibe einen Kommentar