本文整理自网络,侵删。
本文章介绍了Delphi XE6通过WiFiAPI得到WIFI信息,功能是通过Androidapi.JNI.Net.Wifi单元来实现。
具体代码请下载附件后查看。
核心代码:
得到当前连接的WIFI信息
procedure TForm1.SpeedButton1Click(Sender: TObject);
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));
end;
扫描网络环境中的WIFI信息
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
WifiManagerObj: JObject;
WifiManager: JWifiManager;
ScanResult: JScanResult;
i: Integer;
ListBoxItem: TListBoxItem;
begin
WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);
ListBox1.BeginUpdate;
ListBox1.Clear;
for i := 0 to WifiManager.getScanResults.size - 1 do
begin
ScanResult := TJScanResult.Wrap((WifiManager.getScanResults.get(i) as ILocalObject).GetObjectID);
ListBoxItem := TListBoxItem.Create(ListBox1);
ListBoxItem.ItemData.Text := 'SSID: ' + JStringToString(ScanResult.SSID);
ListBoxItem.ItemData.Detail := 'frequency: ' + ScanResult.frequency.ToString +
'MHz' + ' level: ' + ScanResult.level.ToString + 'dBm';
ListBox1.AddObject(ListBoxItem);
end;
ListBox1.EndUpdate;
end;
相关阅读 >>
Delphi adoquery的post和updatebatch
Delphi firedac在后台线程中从mssql server检索记录的方法
更多相关阅读请进入《Delphi》频道 >>