Partial Fix/Workaround for CB-1856. Also removed old deprecated code

This commit is contained in:
Joe Bowser 2012-11-28 14:42:55 -08:00
parent a42dc08756
commit 2c202b82d7

View File

@ -74,6 +74,7 @@ public class NetworkManager extends CordovaPlugin {
ConnectivityManager sockMan; ConnectivityManager sockMan;
BroadcastReceiver receiver; BroadcastReceiver receiver;
private String lastStatus = "";
/** /**
* Constructor. * Constructor.
@ -99,12 +100,11 @@ public class NetworkManager extends CordovaPlugin {
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
if (this.receiver == null) { if (this.receiver == null) {
this.receiver = new BroadcastReceiver() { this.receiver = new BroadcastReceiver() {
@SuppressWarnings("deprecation")
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// (The null check is for the ARM Emulator, please use Intel Emulator for better results) // (The null check is for the ARM Emulator, please use Intel Emulator for better results)
if(NetworkManager.this.webView != null) if(NetworkManager.this.webView != null)
updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO)); updateConnectionInfo(sockMan.getActiveNetworkInfo());
} }
}; };
cordova.getActivity().registerReceiver(this.receiver, intentFilter); cordova.getActivity().registerReceiver(this.receiver, intentFilter);
@ -159,7 +159,14 @@ public class NetworkManager extends CordovaPlugin {
*/ */
private void updateConnectionInfo(NetworkInfo info) { private void updateConnectionInfo(NetworkInfo info) {
// send update to javascript "navigator.network.connection" // 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); type = getType(info);
} }
} }
Log.d("CordovaNetworkManager", "Connection Type: " + type);
return type; return type;
} }
@ -193,7 +201,6 @@ public class NetworkManager extends CordovaPlugin {
result.setKeepCallback(true); result.setKeepCallback(true);
connectionCallbackContext.sendPluginResult(result); connectionCallbackContext.sendPluginResult(result);
} }
webView.postMessage("networkconnection", type); webView.postMessage("networkconnection", type);
} }