unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNIBridge,
Androidapi.JNI.Telephony, Androidapi.JNI.JavaTypes, FMX.Helpers.Android,
FMX.Layouts, FMX.Memo, FMX.ScrollBox, FMX.Controls.Presentation, Androidapi.JNI.Net
;
type
TForm3 = class(TForm)
Memo1: TMemo;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses Androidapi.Helpers;
{$R *.fmx}
//ip地址整数转字符串
function int2Ip(intIP : Int64) : string;
var
n : int64;
ip4, ip3, ip2, ip1: string;
begin
Result := '';
n := intIP shr 24;
intIP := intIP xor (n shl 24);
ip4 := IntToStr(n);
n := intIP shr 16;
intIP := intIP xor (n shl 16);
ip3 := IntToStr(n);
n := intIP shr 8;
intIP := intIP xor (n shl 8);
ip2 := IntToStr(n);
n := intIP;
ip1 := IntToStr(n);
Result := ip1 + '.' + ip2 + '.' + ip3 + '.' + ip4;
end;
//ip地址字符串转整数(没测过)
function ip2Int(const strIP : string): Int64;
var
lst : TStringList;
i : integer;
begin
result := 0;
lst := TStringList.Create;
try
lst.Delimiter := '.';
lst.DelimitedText := strIP;
for i := 0 to lst.Count - 1 do
result := result + StrToInt64(lst[i]) shl (24 - i * 8);
finally
lst.Free;
end;
end;
procedure TForm3.btn1Click(Sender: TObject);
var
Service: JObject;
WifiManager: JWifiManager;
ConnectionInfo: JWifiInfo;
ScanResults: JList;
ScanResult: JScanResult;
I: Integer;
iIP: Int64;
begin
Memo1.Lines.Clear;
Service := SharedActivity.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
WifiManager := TJWifiManager.Wrap((Service as ILocalObject).GetObjectID);
if not WifiManager.isWifiEnabled then
Memo1.Lines.Add('Wifi is disabled')
else
begin
ConnectionInfo := WifiManager.getConnectionInfo;
Memo1.Lines.Add('Connection info');
Memo1.Lines.Add(' SSID: ' + JStringToString(ConnectionInfo.getSSID));
Memo1.Lines.Add(' BSSID: ' + JStringToString(ConnectionInfo.getBSSID));
Memo1.Lines.Add(' IPV4: ' + int2Ip(ConnectionInfo.getIpAddress));
Memo1.Lines.Add(' MAC address: ' + JStringToString(ConnectionInfo.getMacAddress));
ScanResults := WifiManager.getScanResults;
for I := 0 to ScanResults.size - 1 do
begin
Memo1.Lines.Add('');
Memo1.Lines.Add('Detected access point ' + IntToStr(I));
ScanResult := TJScanResult.Wrap((ScanResults.get(I) as ILocalObject).GetObjectID);
Memo1.Lines.Add(' SSID: ' + JStringToString(ScanResult.SSID));
Memo1.Lines.Add(' BSSID: ' + JStringToString(ScanResult.BSSID));
Memo1.Lines.Add(' Capabilities: ' + JStringToString(ScanResult.capabilities));
Memo1.Lines.Add(' Frequency: ' + IntToStr(ScanResult.frequency) + 'MHz');
Memo1.Lines.Add(' Signal level: ' + IntToStr(ScanResult.level) + 'dBm');
end
end
end;
end.