21

As long as I know, There is no API for the method of "Enabling AP" but I can use the reflection to set it on. Here is what I does

wifi_manager = (WifiManager) this.getSystemService(HotSpot_TrisActivity.this.WIFI_SERVICE);
btnEnableAP = (Button)findViewById(R.id.btnEnableAP);

btnEnableAP.setOnClickListener(new View.OnClickListener() 
{

   @Override
   public void onClick(View arg0) 
   {
      // TODO Auto-generated method stub
      WifiConfiguration wifi_configuration = null;
      wifi_manager.setWifiEnabled(false);

      try 
      {
         //USE REFLECTION TO GET METHOD "SetWifiAPEnabled"
         Method method=wifi_manager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
         method.invoke(wifi_manager, wifi_configuration, true);
      } 
      catch (NoSuchMethodException e) 
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } 
      catch (IllegalArgumentException e) 
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } 
      catch (IllegalAccessException e) 
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } 
      catch (InvocationTargetException e) 
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
});
Roman C
  • 49,761
  • 33
  • 66
  • 176
TrisNguyen
  • 591
  • 3
  • 8
  • 15
  • then what is issue you are facing currently? because your code looking right for enabling hotspot – ρяσѕρєя K Dec 19 '12 at 06:29
  • 1
    Yes, it turns on hotspot alright. But now I'm facing the new problems. 1.How to change our hotspot device IP programmatically ?? 2.How can we config DHCP options like, IP distribution range ?? Are there any methods that can do things like that ?? – TrisNguyen Dec 19 '12 at 16:43
  • It's an interesting post, there is no WifiAPManager in SDK. anyway to manage this? like creating a hotspot with custom SSID, private key etc... – TecHunter Apr 28 '14 at 22:32

0 Answers0