开发者

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

开发者 https://www.devze.com 2023-04-03 12:46 出处:网络
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?

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

精彩评论

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

关注公众号