团队博客7
手机自动创建一个wifi热点:
private boolean flag = false;
Toast.makeText(getApplicationContext(), "当前的网络连接不可用", Toast.LENGTH_SHORT).show(); //如果是打开状态就关闭,如果是关闭就打开 flag = !flag; setWifi(flag); public boolean setWifi(boolean enabled){ if(enabled){ //wifi和热点不能同时打开 wifiManager.setWifiEnabled(false); } try{ //配置热点 WifiConfiguration apConfig = new WifiConfiguration(); //配置热点的名称 apConfig.SSID="SUCHUANREDIAN"; //配置热点的密码 apConfig.preSharedKey="12345678"; //通过反射调试设置热点 Method method = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,Boolean.TYPE); //返回热点打开状态 return (Boolean)method.invoke(wifiManager, apConfig,enabled); }catch(Exception e){ return false; } }