开发者

Android SDK WifiManager methods won't work?

For some reasons, this ain't working:

    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    if(wifi.isWifiEnabled())
    {
        tvStatus.setText("You WiFi is enabled");
    }
    else
    {
        tvStatus.setText("You WiFi is disabled");
    }

Why aint this working, am i missing something? And it compiles and everything but when i want to run it on my phone it gives me a force开发者_如何转开发 quit error


Make sure you have the right permissions for using WiFi declared in your Manifest. I think you will be needing ACCESS_WIFI_STATE at a mininum, or if you wish to enable WiFi too, then CHANGE_WIFI_STATE will come in handy.


ConnectivityManager conMgr;
NetworkInfo netInfo;
WifiManager wifiMgr;

conMgr=(ConnectivityManager)getSystemService(context.WIFI_Service);
netInfo=conMgr.getActiveNetworkInfo();
if(!(netInfo==null))
{
if(WifiMgr.isWifiEnabled())
{
//wifi  enabled
}
else
{
//wifi disabled i.e not available
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜