title: How do I change the Portable Hotspot's SSID in Android programmatically?
body: <p>I want change the Hotspot SSID! Can anybody help?</p>
  
  <p>From <a href="https://stackoverflow.com/questions/6394599/android-turn-on-off-wifi-hotspot-programmatically">Android turn On/Off WiFi HotSpot programmatically</a>, here is my code to toggle the Portable Hotspot:</p>
  
  <pre><code>import android.content.*;import android.net.wifi.*;
  import java.lang.reflect.*;
  
  public class ApManager {
  
  //check whether wifi hotspot on or off
  public static boolean isApOn(Context context) {
  WifiManager wifimanager = (WifiManager)  context.getSystemService(context.WIFI_SERVICE);     
  try {
      Method method = wifimanager.getClass().getDeclaredMethod("isWifiApEnabled");
      method.setAccessible(true);
      return (Boolean) method.invoke(wifimanager);
  }
  catch (Throwable ignored) {}
  return false;
  }
  
  // toggle wifi hotspot on or off
  public static boolean configApState(Context context) {
  WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
  WifiConfiguration wificonfiguration = null;
  try {  
      // if WiFi is on, turn it off
      if(isApOn(context)) {               
          wifimanager.setWifiEnabled(false);
      }               
      Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);                   
      method.invoke(wifimanager, wificonfiguration, !isApOn(context));
      return true;
  } 
  catch (Exception e) {
      e.printStackTrace();
  }       
  return false;
  }
  } // end of class
  </code></pre>