0
因此,在我的應用程序中,我使用SSID和網絡密鑰連接到WiFi網絡。它運行良好,如果使用廣播接收器連接成功,用戶會收到通知。現在我只需要告訴用戶是否有認證問題(即給定的密鑰不正確)。據我所知,WifiInfo類有getSupplicantState()方法,但它沒有提供足夠的Supplicant State來滿足我的需求。任何有關此事的幫助將非常感激。如何判斷WPA密鑰是否不正確Android
這是我目前的Wifi Broadcast Receiver onReceive方法;
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conMan.getActiveNetworkInfo();
if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
Log.d("WifiReceiver", "Have Wifi Connection");
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String scannedSSID = sp.getString("SSID", "");
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
String SSID;
if (connectionInfo != null) {
SSID = connectionInfo.getSSID();
Log.d("WifiReceiver", "SSID is " + SSID);
Log.d("WifiReceiver", "Scanned SSID is " + scannedSSID);
String compScanned = "\"" + scannedSSID + "\"";
if (SSID.equalsIgnoreCase(compScanned)) {
Log.d("WifiReceiver", "Connected to " +scannedSSID);
Toast.makeText(context, "Connected to " + scannedSSID, Toast.LENGTH_LONG).show();
context.unregisterReceiver(this);
}
}
else
return;
}
else if (netInfo.isConnectedOrConnecting()) {
Toast.makeText(context, "Connecting...", Toast.LENGTH_LONG).show();
}
else
Log.d("WifiReceiver", "Don't have Wifi Connection");
}