Android - detecting if wifi is WEP, WPA, WPA2, etc. programmatically
There is a way using the ScanResult object.
Something like this:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> networkList = wifi.getScanResults();
//get current connected SSID for comparison to ScanResult
WifiInfo wi = wifi.getConnectionInfo();
String currentSSID = wi.getSSID();
if (networkList != null) {
for (ScanResult network : networkList) {
//check if current connected SSID
if (currentSSID.equals(network.SSID)) {
//get capabilities of current connection
String capabilities = network.capabilities;
Log.d(TAG, network.SSID + " capabilities : " + capabilities);
if (capabilities.contains("WPA2")) {
//do something
} else if (capabilities.contains("WPA")) {
//do something
} else if (capabilities.contains("WEP")) {
//do something
}
}
}
}
References:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#getScanResults()
http://developer.android.com/reference/android/net/wifi/ScanResult.html#capabilities
http://developer.android.com/reference/android/net/wifi/WifiInfo.html
android: Determine security type of wifi networks in range (without connecting to them)
ScanResult capabilities interpretation
How to get scanned wifi networks security type? And what is the network configuration required to connect to particular network using WiFi in android?
See answer given by ayj in this question.
In case link doesn't work in future, let me copy paste it for you here.
You need to parse the ScanResult's capabilities string in the scanComplete method. According to the Android developer documentation, :
ScanResult.capabilities describes the authentication, key management, and
encryption schemes supported by the access point.
You might be able to make use of -- or at the very least use as an example -- the static helper methods available in the AccessPointState class.
- AccessPointState.getScanResultSecurity
- AccessPointState.isEnterprise
Getting whether the wifi connection is locked(password protected) or not
See ScanResult.capabilities
An example is: [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP-CCMP][WPS][ESS]
See this answer if you want to find a way of parsing it.
Basically, if you want to get if it is protected or not:
boolean isProtected = AccessPointState.getScanResultSecurity(scanResult) != AccessPointState.OPEN;
(although it is not nice to compare Strings with the == operator, this will always return the correct answer because the reference in AccessPointState is a static final
one)
Related Topics
How to Lock Orientation During Runtime
How to Make a View with Rounded Corners
Mediaplayer Stutters at Start of Mp3 Playback
Read & Writing Arrays of Parcelable Objects
Popupwindow - Dismiss When Clicked Outside
Android - Save/Restore Fragment State
Activenetworkinfo.Type Is Deprecated in API Level 28
Android Studio, Suddenly Got Gpu Driver Issue When Running Emulator
How to Block a Mobile Number Call and Message Receiving in Android Application Development
How to Set Custom Font for a Whole Application in Android
Cursor Adapter and SQLite Example
Android Studio Not Deploying Changes to App
Using Seekbar to Control Volume in Android
Android Broadcast Receiver Bluetooth Events Catching
Realmchangelistener Does Not Get Called When Realm Gets Updated in Notificationlistenerservice