据我所知,“启用AP”的方法没有API,但我可以使用反射来设置它。这是我所做的
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();
}
}
});