I’m using the following code, in Android application, for monitoring network connections.
ConnectivityManager conMgr =
(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
This code works good if I’m in any Activity, while if I’m in a generic class I can’t call
the method
getSystemService
how can I work around this problem?
if you want to access
getSystemServicein Non Activity class then just pass Current Activity Context to Non Activity class by using Constructor as:and pass Current Activity Context to non Activity class as: