2013年12月13日 星期五

【Android】偵測是否有網路

/* 是否有網路 { */
  ConnectivityManager conManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);//先取得此service
  NetworkInfo networInfo = conManager.getActiveNetworkInfo();       //在取得相關資訊
  if (networInfo == null || !networInfo.isAvailable()){ //判斷是否有網路
   Toast.makeText(this, "未偵測到網路連線", Toast.LENGTH_LONG).show();
   new Thread(new Runnable() {
       
             public void run() {
                 Intent it = new Intent();
        it.setClass(Vegetable.this, Home.class);
        startActivity(it);
             }
         }).start();
  }
/* 是否有網路 } */

沒有留言:

張貼留言