RSS订阅 | 匿名投稿
您的位置:网站首页 > FMX > 正文

Delphi XE6通过WiFiAPI得到WIFI信息

作者:admin 来源: 日期:2014/6/28 9:51:52 人气: 标签:

本文章介绍了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;

 


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: