Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey, Delphi Android, Delphi IOS

Access WIFI Device Info Like SSID And IP Address In Delphi XE6 Firemonkey On Android

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE6 Firemonkey WIFI State Android | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSDeveloper Andrey Yefimov has a blog post up in Russian with an example of reading the WIFI state using the JNI on Android in Delphi XE6 Firemonkey. The example uses the following Android permissions: ACCESS_WIFI_STATE, CHANGE_WIFI_STATE, and
CHANGE_WIFI_MULTICAST_STATE. The wrapper makes the following information available: wifi enabled, wifi state, and ping supplicant. Plus the following additional information: BSSID, HiddenSSID, ip address, link speed, mac address, network ID, RSSI, SSID, and supplicant state. It also shows an example of listing the access point SSIDs which are in range of your Android device. The wrapper is a unit called Androidapi.JNI.Net.Wifi. Here is the sample code for reading the wifi information with the wrapper:
var
WifiManagerObj: JObject;
WifiManager: JWifiManager;
WifiInfo: JWifiInfo;
begin
WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);
WifiInfo := WifiManager.getConnectionInfo();

Label1.Text := 'Wifi Enabled: ' + WifiManager.isWifiEnabled.ToString;
Label2.Text := 'Wifi State: ' + WifiManager.getWifiState.ToString;
Label3.Text := 'Ping Supplicant: ' + WifiManager.pingSupplicant.ToString;

Memo1.Lines.Clear;
Memo1.Lines.Add('BSSID: ' + JStringToString(WifiInfo.getBSSID));
Memo1.Lines.Add('HiddenSSID: ' + WifiInfo.getHiddenSSID.ToString);
Memo1.Lines.Add('IpAddress: ' + WifiInfo.getIpAddress.ToString);
Memo1.Lines.Add('LinkSpeed: ' + WifiInfo.getLinkSpeed.ToString + 'Mbps');
Memo1.Lines.Add('MacAddress: ' + JStringToString(WifiInfo.getMacAddress));
Memo1.Lines.Add('NetworkId: ' + WifiInfo.getNetworkId.ToString);
Memo1.Lines.Add('Rssi: ' + WifiInfo.getRssi.ToString + 'dBm');
Memo1.Lines.Add('SSID: ' + JStringToString(WifiInfo.getSSID));
Memo1.Lines.Add('SupplicantState: ' + JStringToString(WifiInfo.getSupplicantState.toString));
The original blog post is in Russian so use Google Chrome to translate. This code should also work in AppMethod.

Head over and check out the full blog post for reading the wifi state using the JNI in Delphi XE6 Firemonkey on Android.

Or download a mirror of the WIFI State JNI example.

Exit mobile version