diff --git a/framework/src/org/apache/cordova/NetworkManager.java b/framework/src/org/apache/cordova/NetworkManager.java index af2fc7d3..bb4743f2 100755 --- a/framework/src/org/apache/cordova/NetworkManager.java +++ b/framework/src/org/apache/cordova/NetworkManager.java @@ -74,6 +74,7 @@ public class NetworkManager extends CordovaPlugin { ConnectivityManager sockMan; BroadcastReceiver receiver; + private String lastStatus = ""; /** * Constructor. @@ -99,12 +100,11 @@ public class NetworkManager extends CordovaPlugin { intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { - @SuppressWarnings("deprecation") @Override public void onReceive(Context context, Intent intent) { // (The null check is for the ARM Emulator, please use Intel Emulator for better results) - if(NetworkManager.this.webView != null) - updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO)); + if(NetworkManager.this.webView != null) + updateConnectionInfo(sockMan.getActiveNetworkInfo()); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); @@ -159,7 +159,14 @@ public class NetworkManager extends CordovaPlugin { */ private void updateConnectionInfo(NetworkInfo info) { // send update to javascript "navigator.network.connection" - sendUpdate(this.getConnectionInfo(info)); + // Jellybean sends its own info + String thisStatus = this.getConnectionInfo(info); + if(!thisStatus.equals(lastStatus)) + { + sendUpdate(thisStatus); + lastStatus = thisStatus; + } + } /** @@ -179,6 +186,7 @@ public class NetworkManager extends CordovaPlugin { type = getType(info); } } + Log.d("CordovaNetworkManager", "Connection Type: " + type); return type; } @@ -193,7 +201,6 @@ public class NetworkManager extends CordovaPlugin { result.setKeepCallback(true); connectionCallbackContext.sendPluginResult(result); } - webView.postMessage("networkconnection", type); }