How to check network connectivity in android with out using activity
Ho开发者_Go百科w to check network connectivity in android with out using activity, check it from business object package.
public class DataProviderFactory {
public IDataProvider getDataProvider()
{
//check for the internet connection, if exist
boolean connection_exist=isNetworkAvailable();
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
but its working well in Activities.But I want to check it from the businuss object package, that is inside a class without using activities.
Pass a Context
into the class and use that to get the SystemService
.
精彩评论