mirror of
https://gitee.com/shuto/cordova-plugin-network-information.git
synced 2025-03-10 18:31:03 +08:00
CB-7976 Android: Use webView's context rather than Activity's context for intent receiver
This commit is contained in:
parent
9dc1796c59
commit
165b4f0120
@ -76,19 +76,11 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
private static final String LOG_TAG = "NetworkManager";
|
private static final String LOG_TAG = "NetworkManager";
|
||||||
|
|
||||||
private CallbackContext connectionCallbackContext;
|
private CallbackContext connectionCallbackContext;
|
||||||
private boolean registered = false;
|
|
||||||
|
|
||||||
ConnectivityManager sockMan;
|
ConnectivityManager sockMan;
|
||||||
BroadcastReceiver receiver;
|
BroadcastReceiver receiver;
|
||||||
private JSONObject lastInfo = null;
|
private JSONObject lastInfo = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
public NetworkManager() {
|
|
||||||
this.receiver = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Sets the context of the Command. This can then be used to do things like
|
||||||
* get file paths associated with the Activity.
|
* get file paths associated with the Activity.
|
||||||
@ -113,8 +105,7 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
updateConnectionInfo(sockMan.getActiveNetworkInfo());
|
updateConnectionInfo(sockMan.getActiveNetworkInfo());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
cordova.getActivity().registerReceiver(this.receiver, intentFilter);
|
webView.getContext().registerReceiver(this.receiver, intentFilter);
|
||||||
this.registered = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -148,12 +139,13 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
* Stop network receiver.
|
* Stop network receiver.
|
||||||
*/
|
*/
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (this.receiver != null && this.registered) {
|
if (this.receiver != null) {
|
||||||
try {
|
try {
|
||||||
this.cordova.getActivity().unregisterReceiver(this.receiver);
|
webView.getContext().unregisterReceiver(this.receiver);
|
||||||
this.registered = false;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e);
|
Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
receiver = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,4 +265,3 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
return TYPE_UNKNOWN;
|
return TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user