I am trying to find out if there is a Wifi API for Java. Something that can connect to Wifi networks and scan them (to find devices). I can't seem to find something like that. Any suggestions? Thanks!
P.S. I know about the WifiManager for Android, but I am not developing for Android, I am developing with JDK 6.
The Network Information API provides information about the system's connection in terms of general connection type (e.g., 'wifi, 'cellular', etc.). This can be used to select high definition content or low definition content based on the user's connection.
First and foremost, add permissions in your manifest file. These 4 permissions are required to make changes in your device network connectivity. Setup configuration to connect one specific wifi using WifiConfiguration. WifiConfiguration config = new WifiConfiguration();
In Network and Sharing Center, next to Connections, select your Wi-Fi network name. In Wi-Fi Status, select Wireless Properties. In Wireless Network Properties, select the Security tab, then select the Show characters check box. Your Wi-Fi network password is displayed in the Network security key box.
Description. WiFi Manager Lite allows you to manage wireless networks. The application gets you the ability to connect, view details about the wireless networks and set up networks. Moreover, you can manage multiple wireless network profiles.
You can take help of command line tools to get list of available networks using command "netsh wlan show networks mode=Bssid". Try below java method.
public static ArrayList scanWiFi() {
ArrayList<String> networkList = new ArrayList<>();
try {
// Execute command
String command = "netsh wlan show networks mode=Bssid";
Process p = Runtime.getRuntime().exec(command);
try {
p.waitFor();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream())
);
String line;
StringBuilder sb = new StringBuilder();
String ssidArr[];
while ((line = reader.readLine()) != null) {
//System.out.println(line);
if (line.contains("SSID ") && !line.contains("BSSID ")) {
sb.append(line);
networkList.add(line.split(":")[1]);
//System.out.println("data : " + ssidArr[1]);
}
}
//System.out.println(networkList);
} catch (IOException e) {
}
return networkList;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With