Change WiFi hotspot's SSID and password in Android Oreo 8.x

心不动则不痛 提交于 2019-12-03 09:40:23

I have only a partial solution to the problem. Hopefully, it will be sufficient for the application you are designing.

The SSID and the password are hard-coded by the android system when you start the Hotspot. By looking over at the AOSP code, I see that the same hotspot can be shared by multiple applications. The configuration for this hotspot(class name is WifiConfiguration) is also shared with all the requesting applications. This configuration is passed back to the application in the callback onStarted(LocalOnlyHotspotReservation reservation). You can get the WifiConfiguration by calling reservation.getWifiConfiguration(). You will get all the information you need from the WifiConfiguration object. So you can read the Pre-Shared Key and the access point name. But I don't think you can change them


FYI, The relevant code that sets up the wifi configuration (including the hard-coded SSID and WPA2-PSK key) is done by the following piece of code

  /**
   * Generate a temporary WPA2 based configuration for use by the local only hotspot.
   * This config is not persisted and will not be stored by the WifiApConfigStore.
   */
   public static WifiConfiguration generateLocalOnlyHotspotConfig(Context context) {
       WifiConfiguration config = new WifiConfiguration();
       config.SSID = context.getResources().getString(
              R.string.wifi_localhotspot_configure_ssid_default) + "_"
                      + getRandomIntForDefaultSsid();
       config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
       config.networkId = WifiConfiguration.LOCAL_ONLY_NETWORK_ID;
       String randomUUID = UUID.randomUUID().toString();
       // first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
       config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
       return config;
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!