我正在使用此代码获取wifi SSID列表
WifiManager wifimanager = (WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
List<ScanResult> mScanResults = wifimanager.getScanResults();
ArrayList<String> statut = new ArrayList<String>() ;
for(ScanResult results : mScanResults){
Log.e("result",results.SSID);
statut.add(results.SSID);}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item,statut);
spinner = (Spinner) rootView.findViewById(R.id.spinner);
spinner.setAdapter(adapter);
现在我想为每个SSID提取WIFI安全名称(WPA / WPA2 / PSK)。 任何帮助将不胜感激。
答案 0 :(得分:0)
你可以尝试下面的代码:
private String getScanResultSecurity(ScanResult scanResult){
String capabilities = scanResult.capabilities;
String securityModes[] = { Constants.WEP, Constants.PSK, Constants.EAP};
for(int i = 0; i < securityModes.length; i++){
if(capabilities.contains(securityModes[i])){
return securityModes[i];
}
}
return Constants.OPEN;
}
public class Constants {
// Constants used for different security types
public static final String PSK = "PSK";
public static final String WEP = "WEP";
public static final String EAP = "EAP";
public static final String OPEN = "Open";
}