开发者

How to check the WIFI and shared access point are activated in the Android OS?

I have a problem that I want to check the user who starts the WIFI or turns into AP in Android OS.

How 开发者_Go百科should I check these services whether they are activated or not?

Please help me to solve this problem.

Thank you for your help:)


To check the Wifi state use this code

private WifiManager wifiManager;
@Override
public void onCreate(Bundle icicle) {
    ....................
     wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    if(wifiManager.isWifiEnabled()){
         // do whatever you wnat
         wifiManager.setWifiEnabled(false);
    }else{
       // do whatever you wnat
       wifiManager.setWifiEnabled(true);
    }
}

To perform this you have to declare the bellow permissions in the manifest.xml file.

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜