开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜