HTC 通过 WifiConfiguration 修改 SSID
http://www.dewen.org/q/5419
public void setHTCSSID(WifiConfiguration config, String ssid){ Field localField1; try { localField1 = WifiConfiguration.class.getDeclaredField("mWifiApProfile"); localField1.setAccessible(true); Object localObject2 = localField1.get(config); localField1.setAccessible(false); if(localObject2!=null){ Field localField5 = localObject2.getClass().getDeclaredField("SSID"); localField5.setAccessible(true); localField5.set(localObject2, ssid); localField5.setAccessible(false); } } catch(Exception e) { e.printStackTrace(); } }
http://blog.sina.com.cn/s/blog_53dd443a010109i8.html
mnetConfig = new Wificonfiguration(); …. Field localField1; try { localField1 = WifiConfiguration.class.getDeclaredField("mWifiApProfile"); localField1.setAccessible(true); Object localObject2 = localField1.get(mnetConfig); localField1.setAccessible(false); if(localObject2!=null){ Field localField5 = localObject2.getClass().getDeclaredField("SSID"); localField5.setAccessible(true); localField5.set(localObject2, netConfig.SSID); localField5.setAccessible(false); Field localField4 = localObject2.getClass().getDeclaredField("BSSID"); localField4.setAccessible(true); localField4.set(localObject2, netConfig.BSSID); localField4.setAccessible(false); } } catch(Exception e) { e.printStackTrace(); }
HTC Android Hotspot 热点配置 之DHCP
最近在研究手机热点的建立。HTC手机比较坑爹,首先一个,是不能按常规的办法修改 SSID, BSSID,
在网上搜了下,有篇博客把这个问题解决了,请参考:http://blog.sina.com.cn/s/blog_adc221ac01011mrs.html
private boolean setWifiSSIDForHTC(WifiConfiguration apConfig) { boolean successed = true; // WifiConfiguration mnetConfig = new WifiConfiguration(); Field localField1; try { localField1 = WifiConfiguration.class.getDeclaredField("mWifiApProfile"); localField1.setAccessible(true); Object localObject2 = localField1.get(apConfig); localField1.setAccessible(false); if(localObject2!=null){ Field localField5 = localObject2.getClass().getDeclaredField("SSID"); localField5.setAccessible(true); localField5.set(localObject2, apConfig.SSID);// netConfig.SSID); localField5.setAccessible(false); Field localField4 = localObject2.getClass().getDeclaredField("BSSID"); localField4.setAccessible(true); localField4.set(localObject2, apConfig.BSSID);//netConfig.BSSID); localField4.setAccessible(false); Field localField6 = localObject2.getClass().getDeclaredField("dhcpEnable"); localField6.setAccessible(true); // localField6.set(localObject2, "true");//netConfig.BSSID); localField6.setInt(localObject2, 1); localField6.setAccessible(false); } } catch(Exception e) { e.printStackTrace(); } return successed; }
// 解决HTC热点设置问题 try { Field localField1 = WifiConfiguration.class .getDeclaredField("mWifiApProfile"); localField1.setAccessible(true); Object localObject2 = localField1.get(config); localField1.setAccessible(false); if (localObject2 != null) { // SSID设置 Field localField5 = localObject2.getClass().getDeclaredField( "SSID"); localField5.setAccessible(true); localField5.set(localObject2, config.SSID); localField5.setAccessible(false); // IP地址设置 Field localField4 = localObject2.getClass().getDeclaredField( "ipAddress"); localField4.setAccessible(true); localField4.set(localObject2, "192.168.1.1"); localField4.setAccessible(false); // 子网掩码设置 Field localField6 = localObject2.getClass().getDeclaredField( "dhcpSubnetMask"); localField6.setAccessible(true); localField6.set(localObject2, "255.255.255.0"); localField6.setAccessible(false); // 安全类型设置 Field localField2 = localObject2.getClass().getDeclaredField( "secureType"); localField2.setAccessible(true); if (appwd.equals("")) { localField2.set(localObject2, "open"); } else { localField2.set(localObject2, "wpa2-psk"); } localField2.setAccessible(false); // 密码设置 Field localField3 = localObject2.getClass().getDeclaredField( "key"); localField3.setAccessible(true); localField3.set(localObject2, config.preSharedKey); localField3.setAccessible(false); // 起始IP设置 Field localField8 = localObject2.getClass().getDeclaredField( "startingIP"); localField8.setAccessible(true); localField8.set(localObject2, "192.168.1.100"); localField8.setAccessible(false); // DHCP设置 Field localField7 = localObject2.getClass().getDeclaredField( "dhcpEnable"); localField7.setAccessible(true); localField7.set(localObject2, 1); localField7.setAccessible(false); } } catch (Exception e) { System.out.println(e); } // HTC热点设置完毕