首页 > 代码库 > phonegap 检查是否有网络

phonegap 检查是否有网络

在主active onCreate函数中实现

    @Override    public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         super.setBooleanProperty("loadInWebView", true);            super.setIntegerProperty("splashscreen", R.drawable.a);          ConnectivityManager cwjManager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);          NetworkInfo info = cwjManager.getActiveNetworkInfo();          if (info != null && info.isAvailable()){ //有网          super.loadUrl("http://192.168.55.175:5000",10000);          }else{//没有网         super.loadUrl("file:///android_asset/www/error.html",2000);          }    }

 

phonegap 检查是否有网络