Exemple #1
0
 public String getIpAssignment() {
   Log.d(TAG, "<<<<<<<<<<<getNetworkTypeName() <<<<<<<<<" + getNetworkTypeName());
   if (getNetworkTypeName().equals("WIFI")) {
     Log.d(TAG, "<<<<<<<<<<<当前网络为wifi<<<<<<<<<");
     WifiManager wm = (WifiManager) mContext.getSystemService(mContext.WIFI_SERVICE);
     if (wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
       WifiInfo wifiInfo = wm.getConnectionInfo();
       String ssid = wifiInfo.getSSID();
       List<WifiConfiguration> wifiConfigurations = wm.getConfiguredNetworks();
       for (WifiConfiguration config : wifiConfigurations) {
         if (config.SSID.equals(ssid)) {
           String IP_Assignment = config.toString();
           Log.i(TAG, "WIFI_IP_Assignment: " + IP_Assignment);
           String[] sss = IP_Assignment.split("\n");
           Log.i(TAG, "<<<<<<String[] sss<<<<<<< " + sss.length + "<<<<<<");
           IP_Assignment = sss[20];
           IP_Assignment = IP_Assignment.substring(IP_Assignment.lastIndexOf(":") + 1).toString();
           return IP_Assignment;
         }
       }
     }
     return "UNASSIGNED";
   } else {
     String Ip_Assignment = null;
     // ContentResolver cr = mContext.getContentResolver();
     // try {
     // if (Settings.System.getInt(cr, ETHERNET_USE_STATIC_IP) == 0) {
     // Log.d(TAG,
     // "checkUseStaticIp() : user set to use DHCP, about to Return.");
     //
     // Ip_Assignment = "DHCP";
     // }
     // Ip_Assignment = "STATIC";
     // } catch (Settings.SettingNotFoundException e) {
     // Ip_Assignment = "DHCP";
     // }
     // Log.i(TAG, "ETHERNET_IP_Assignment: " + Ip_Assignment);
     IpConfiguration mIpConfiguration = new IpConfiguration();
     mIpConfiguration.getIpAssignment();
     Log.d(TAG, "ipassignment" + mIpConfiguration.getIpAssignment());
     // return Ip_Assignment;
     if (mIpConfiguration.getIpAssignment().equals(IpAssignment.DHCP)) {
       return "DHCP";
     } else {
       return "STATIC";
     }
     //			return mIpConfiguration.getIpAssignment();
   }
 }
 public boolean isUserConfig(WifiConfiguration config) {
   if (config == null || config.SSID == null) return false;
   if (getKeyType(config) != KeyMgmt.NONE) return true;
   if (config.SSID.equals(servalConfiguration.SSID)) return false;
   return !config.SSID.toLowerCase().contains("serval");
 }