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

首頁 > 系統 > Android > 正文

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

2019-12-12 01:13:38
字體:
來源:轉載
供稿:網友

其中定義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的方法 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 罗平县| 随州市| 九寨沟县| 宁安市| 彝良县| 宜宾市| 咸阳市| 花垣县| 江津市| 道真| 周宁县| 锡林浩特市| 古交市| 兰溪市| 施甸县| 中宁县| 新宾| 竹北市| 富川| 江达县| 会宁县| 石屏县| 全椒县| 弥勒县| 浑源县| 通榆县| 资源县| 磐石市| 武平县| 崇左市| 东明县| 东莞市| 南投县| 唐海县| 慈利县| 闸北区| 沁水县| 平罗县| 通辽市| 栾城县| 桐庐县|