有没有人遇到过
的问题I/WifiManager(22480): setWifiEnabled : true
E/WifiManager(22480): java.lang.Throwable
E/WifiManager(22480): at android.net.wifi.WifiManager.setWifiEnabled(WifiManager.java:959)
当通过Android API打开或关闭Wi-Fi无线电时,我似乎正在发生这种情况。它正在下面的函数中使用:
public static void manageWiFiRadio(Context context, String onoff)
{
Log.d(TAG, "managerWiFiRadio(context, " + onoff + " )");
try
{
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
Thread.sleep(250);
if ( onoff == "on")
{
if(!wifiManager.isWifiEnabled())
{
Thread.sleep(250);
wifiManager.setWifiEnabled(true);
}
else Log.d(TAG,"WiFi is already" + onoff);
}
else if( onoff == "off")
{
if(wifiManager.isWifiEnabled())
{
Thread.sleep(250);
wifiManager.setWifiEnabled(false);
}
else Log.d(TAG,"WiFi is already" + onoff);
}
}
catch (Exception e) {Log.d(TAG, "There was an exception in wifi e:" + e);}
wifiManager = null;
}
我在上面添加了睡眠以进行调试,但这只会降低再现率。
为了进行测试,我在Sprint三星Galaxy S III和Sprint HTC Evo 4G上执行了此操作,两者都遇到了这个问题。当抛出错误时,它会被Android操作系统捕获,但Wi-Fi无线电永远不会改变状态。
答案 0 :(得分:0)
更改
Thread.sleep(250);
wifiManager.setWifiEnabled(false);
到
wifiManager.setWifiEnabled(false);
Thread.sleep(250);