![](/img/trans.png)
[英]how to open configure portable Wi-Fi hotspot setting by onclick?
[英]Use java code to enable portable wi-fi hotspot
目前,我正在為我的Android手機構建一個非常小的本機應用程序。 當我單擊應用程序中的一個按鈕時,我想激活便攜式wi-fi熱點。 但是我不知道如何調用Android API來激活便攜式wi-fi熱點。 我知道如何通過用戶界面進行操作。 誰能告訴我?
// code to enable portable wifi hotspot
public void EnableWifiHotspot(){
try{
WifiManager wifi_manager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wifi_configuration = null;
Method wifiHotspotEnabledMethod=wifi_manager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
wifiHotspotEnabledMethod.invoke(wifi_manager, wifi_configuration, true);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
//code for disabling portable wifi hotspot
public void DisableWifiHotspot(){
try{
WifiManager wifi_manager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wifi_configuration = null;
Method wifiHotspotEnabledMethod=wifi_manager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
wifiHotspotEnabledMethod.invoke(wifi_manager, wifi_configuration, false);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.