How to check the WIFI and shared access point are activated in the Android OS?
-
28-10-2019 - |
سؤال
I have a problem that I want to check the user who starts the WIFI or turns into AP in Android OS.
How 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>
لا تنتمي إلى StackOverflow