From 346ed60f0d986c8afef5695e0fc59dc60e912716 Mon Sep 17 00:00:00 2001 From: macdonst Date: Fri, 6 May 2011 04:18:35 +0800 Subject: [PATCH] Android 2.2+ supports W3C Connection API For Android version 2.2 or better the navigator.connection object already exists. If this case we should immediately fire the onPhoneGapConnectionReady event so we don't tie up the 'deviceready' event. --- framework/assets/js/network.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/framework/assets/js/network.js b/framework/assets/js/network.js index b7e6bfea..5d8a9fcb 100755 --- a/framework/assets/js/network.js +++ b/framework/assets/js/network.js @@ -96,18 +96,6 @@ Connection.NONE = 20; * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL) */ Connection.prototype.getInfo = function(successCallback, errorCallback) { - // successCallback required - if (typeof successCallback !== "function") { - console.log("Connection Error: successCallback is not a function"); - return; - } - - // errorCallback optional - if (errorCallback && (typeof errorCallback !== "function")) { - console.log("Connection Error: errorCallback is not a function"); - return; - } - // Get info PhoneGap.exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []); }; @@ -117,8 +105,13 @@ PhoneGap.addConstructor(function() { if (typeof navigator.network === "undefined") { navigator.network = new Network(); } + // No native connection object for Android 2.1 or earlier, so use PhoneGap connection if (typeof navigator.connection === "undefined") { navigator.connection = new Connection(); } + // If Android 2.2+ then fire the connection ready event + else { + PhoneGap.onPhoneGapConnectionReady.fire(); + } }); };