本文整理自网络,侵删。
介绍
本文章介绍了Delphi XE7实现手机上获取wifi信息的程序,具体代码如下,或者直接下载附件
unit Main;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, FMX.Memo;
type
TFormMain = class(TForm)
ButtonInfo: TButton;
Memo: TMemo;
procedure ButtonInfoClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormMain: TFormMain;
implementation
uses Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText, android.net.wifi;
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID}
procedure TFormMain.ButtonInfoClick(Sender: TObject);
var
Service: JObject;
WifiManager: JWifiManager;
ConnectionInfo: JWifiInfo;
ScanResults: JList;
ScanResult: JScanResult;
I: Integer;
begin
Memo.Lines.Clear;
Service := SharedActivity.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
WifiManager := TJWifiManager.Wrap((Service as ILocalObject).GetObjectID);
if not WifiManager.isWifiEnabled then
Memo.Lines.Add('Wifi is disabled')
else
begin
ConnectionInfo := WifiManager.getConnectionInfo;
Memo.Lines.Add('Connection info');
Memo.Lines.Add(' SSID: ' + JStringToString(ConnectionInfo.getSSID));
Memo.Lines.Add(' BSSID: ' + JStringToString(ConnectionInfo.getBSSID));
Memo.Lines.Add(' MAC address: ' + JStringToString(ConnectionInfo.getMacAddress));
ScanResults := WifiManager.getScanResults;
for I := 0 to ScanResults.size - 1 do
begin
Memo.Lines.Add('');
Memo.Lines.Add('Detected access point ' + IntToStr(I));
ScanResult := TJScanResult.Wrap((ScanResults.get(I) as ILocalObject).GetObjectID);
Memo.Lines.Add(' SSID: ' + JStringToString(ScanResult.SSID));
Memo.Lines.Add(' BSSID: ' + JStringToString(ScanResult.BSSID));
Memo.Lines.Add(' Capabilities: ' + JStringToString(ScanResult.capabilities));
Memo.Lines.Add(' Frequency: ' + IntToStr(ScanResult.frequency) + 'MHz');
Memo.Lines.Add(' Signal level: ' + IntToStr(ScanResult.level) + 'dBm');
end
end
end;
end.
相关阅读 >>
Delphi 详解 enumwindows 与 enumwindowsproc
Delphi 10 下提示sharedactivitycontext错误的解决方法
更多相关阅读请进入《Delphi》频道 >>