国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android獲取熱點主機ip和連接熱點手機ip的代碼

2019-10-22 18:16:11
字體:
來源:轉載
供稿:網友

其中定義WIFI AP的幾個狀態

public static final int WIFI_AP_STATE_DISABLING = 10;  public static final int WIFI_AP_STATE_DISABLED = 11;  public static final int WIFI_AP_STATE_ENABLING = 12;  public static final int WIFI_AP_STATE_ENABLED = 13;  public static final int WIFI_AP_STATE_FAILED = 14;  

對應于WifiMangaer.java中對這幾個狀態的定義。

獲取WIFI熱點的狀態:

public int getWifiApState(Context mContext) {    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);      try {        Method method = wifiManager.getClass().getMethod("getWifiApState");        int i = (Integer) method.invoke(wifiManager);        Log.i(TAG,"wifi state: " + i);        return i;      } catch (Exception e) {        Log.e(TAG,"Cannot get WiFi AP state" + e);        return WIFI_AP_STATE_FAILED;      }    }  

判斷Wifi熱點是否可用:

private ArrayList<String> getConnectedHotIP() {   ArrayList<String> connectedIP = new ArrayList<String>();   try {     BufferedReader br = new BufferedReader(new FileReader(         "/proc/net/arp"));     String line;     while ((line = br.readLine()) != null) {       String[] splitted = line.split(" +");       if (splitted != null && splitted.length >= 4) {         String ip = splitted[0];         connectedIP.add(ip);       }     }   } catch (Exception e) {     e.printStackTrace();   }   return connectedIP; } //輸出鏈接到當前設備的IP地址 public void printHotIp() {   ArrayList<String> connectedIP = getConnectedHotIP();   StringBuilder resultList = new StringBuilder();   for (String ip : connectedIP) {     resultList.append(ip);     resultList.append("/n");   }   System.out.print(resultList);   Log.d(TAG,"---->>heww resultList="+resultList); } 

當然在應用中要添加訪問WIFI設備的權限:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 

獲取熱點主機ip地址的代碼:

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);      DhcpInfo info=wifiManager.getDhcpInfo();      System.out.println(info.serverAddress);

總結

以上所述是小編給大家介紹的Android獲取熱點主機ip和連接熱點手機ip的方法 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大邑县| 浦县| 庆元县| 福安市| 旺苍县| 贵定县| 青岛市| 乌拉特中旗| 浦北县| 确山县| 田阳县| 铁岭县| 哈巴河县| 顺平县| 连江县| 武宁县| 裕民县| 望都县| 河西区| 黄龙县| 泽库县| 勐海县| 湘乡市| 武穴市| 定兴县| 改则县| 嵊州市| 泽州县| 荔浦县| 本溪市| 北安市| 长垣县| 佛学| 平湖市| 咸宁市| 九江市| 建昌县| 九龙县| 襄樊市| 乌海市| 余江县|