title: Android 6.0.1 couldn't enable wifi hotspot programmatically
body: <p>When I tried to enable wifi tethering from the following code it throws the exception</p>
  <blockquote>
  <p>java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.....</p>
  <p>.... not granted  this permission: android.permission.WRITE_SETTINGS</p>
  </blockquote>
  <p>But this works fine in android 6.0 and below versions. And also tried with giving <em><strong>android.permission.WRITE_SETTINGS</strong></em> too.</p>
  <p>Is there any limitation in accessing wifiAP in android 6.1?</p>
  <p>Follow I attached the code sample that I used to enable hotspot.</p>
  <pre><code>            WifiConfiguration netConfig = new WifiConfiguration();
              netConfig.SSID = ssId;
              netConfig.preSharedKey = passkey;
              netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
              netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
              
              try {
                  boolean apstatus = (Boolean) method.invoke(wifiManager, netConfig, true);
                  
                  for (Method isWifiApEnabledmethod : wmMethods) {
                      if (isWifiApEnabledmethod.getName().equals(&quot;isWifiApEnabled&quot;)) {
                          while (!(Boolean) isWifiApEnabledmethod.invoke(wifiManager)) {}
  
                          for (Method method1 : wmMethods) {
                              if (method1.getName().equals(&quot;getWifiApState&quot;)) {
                                  int apstate;
                                  apstate = (Integer) method1.invoke(wifiManager);
                                  Log.i(TAG, &quot;Apstate ::: &quot; + apstate);
                              }
                          }
                      }
                  }
                  
                  if (apstatus) {
                      Log.d(TAG, &quot;Access Point created&quot;);
                  } else {
                      Log.d(TAG, &quot;Access Point creation failed&quot;);
                  }
  
              } catch (IllegalArgumentException e) {
                  e.printStackTrace();
              } catch (IllegalAccessException e) {
                  e.printStackTrace();
              } catch (InvocationTargetException e) {
                  e.printStackTrace();
              }
  </code></pre>