Android实例-获取安卓手机WIFI信息(XE8+小米2)

Android实例-获取安卓手机WIFI信息(XE8+小米2)

结果:

1.必须打开Access wifi state权限,不打开权限会出图二的错误。

相关资料:

http://blog.csdn.net/lyf_lyf/article/category/173576

实例代码:

 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.ScrollBox,
FMX.Memo, FMX.StdCtrls, FMX.Controls.Presentation,
Androidapi.JNI.GraphicsContentViewText,//需要引入
Androidapi.JNIBridge,//需要引入
Androidapi.JNI.Telephony,//需要引入
Androidapi.JNI.JavaTypes,//需要引入
FMX.Helpers.Android,//需要引入
Androidapi.JNI.Net,//需要引入
Androidapi.Helpers;//需要引入 type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} //ip地址整数转字符串
function int2Ip(intIP : Int64) : string;
var
n : int64;
ip4, ip3, ip2, ip1: string;
begin
Result := '';
n := intIP shr ;
intIP := intIP xor (n shl );
ip4 := IntToStr(n); n := intIP shr ;
intIP := intIP xor (n shl );
ip3 := IntToStr(n); n := intIP shr ;
intIP := intIP xor (n shl );
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 := ;
lst := TStringList.Create;
try
lst.Delimiter := '.';
lst.DelimitedText := strIP;
for i := to lst.Count - do
result := result + StrToInt64(lst[i]) shl ( - i * );
finally
lst.Free;
end;
end; procedure TForm1.Button1Click(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禁用')
else
begin
ConnectionInfo := WifiManager.getConnectionInfo;
Memo1.Lines.Add('连接信息');
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 := to ScanResults.size - do
begin
Memo1.Lines.Add('');
Memo1.Lines.Add('检测到的接入点 ' + 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.
上一篇:写一个python脚本监控在linux中的进程


下一篇:web前端学习python之第一章_基础语法(二)