亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android中判斷網(wǎng)絡(luò)是否連接實(shí)例詳解

 更新時(shí)間:2017年01月24日 10:13:45   投稿:lqh  
這篇文章主要介紹了Android中判斷網(wǎng)絡(luò)是否連接實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

Android中判斷網(wǎng)絡(luò)是否連接實(shí)例詳解

在android中,如何監(jiān)測(cè)網(wǎng)絡(luò)的狀態(tài)呢,這個(gè)有的時(shí)候也是十分重要的,方法如下:

public class ConnectionDetector { 
   
  private Context _context; 
   
  public ConnectionDetector(Context context){ 
    this._context = context; 
  } 
 
  public boolean isConnectingToInternet(){ 
    ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE); 
     if (connectivity != null)  
     { 
       NetworkInfo[] info = connectivity.getAllNetworkInfo(); 
       if (info != null)  
         for (int i = 0; i < info.length; i++)  
           if (info[i].getState() == NetworkInfo.State.CONNECTED) 
           { 
             return true; 
           } 
 
     } 
     return false; 
  } 

調(diào)用:

ConnectionDetector cd = new ConnectionDetector(getApplicationContext());  
  
Boolean isInternetPresent = cd.isConnectingToInternet(); //  

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論