2016-12-17 30 views
0

我正在开发一个应用程序,该应用程序一旦启动就会创建一个热点。 这有benn工作正常,直到Android 7牛轧糖来了。 我正在使用WifiApManager class如何在android 7中以编程方式保存接入点设置

就像我说过的一切都很完美,但是当使用API​​ 25时,使用正确的设置(ssid,password等)创建热点,我的笔记本电脑会识别它并连接。

但它有“没有互联网”,因此没有数据交换发生。 Waht我需要做的是去电话热点设置,然后按保存。它将会一次又一次地开启并最终按照它应有的方式工作。

我不知道这是一个android bug还是故意的,但我相信以前的API没有“保存”按钮!?我一直在网上搜索,但找不到任何东西。提前致谢。 kEbO

回答

1
public static boolean setHotspotNameAndPassword(String newName,String password, Context context) { 
     try { 
      WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); 
      Method getConfigMethod = wifiManager.getClass().getMethod("getWifiApConfiguration"); 
      WifiConfiguration wifiConfig = (WifiConfiguration) getConfigMethod.invoke(wifiManager); 
      wifiConfig.preSharedKey=password; 
      wifiConfig.SSID = newName; 

      Method setConfigMethod = wifiManager.getClass().getMethod("setWifiApConfiguration", WifiConfiguration.class); 
      setConfigMethod.invoke(wifiManager, wifiConfig); 
      return true; 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
      return false; 
     } 

这是我的工作!修改设置。

但我无法找到开启/关闭Android 7.0+热点的方式

+0

感谢您的帮助。我按照您在代码中显示的方式执行此操作。打开它我使用'方法method = mWifiManager.getClass()。getMethod(“setWifiApEnabled”,WifiConfiguration.class,boolean.class);'问题是在我的情况下不打开热点,而是与IP一个客户。关心kEbO – kEbO

相关问题