小米wifi设置access_Android实例-获取安卓手机WIFI信息(XE8+小米2)

1 unitUnit1;2

3 interface

4

5 uses

6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.ScrollBox,8 FMX.Memo, FMX.StdCtrls, FMX.Controls.Presentation,9 Androidapi.JNI.GraphicsContentViewText,//需要引入

10 Androidapi.JNIBridge,//需要引入

11 Androidapi.JNI.Telephony,//需要引入

12 Androidapi.JNI.JavaTypes,//需要引入

13 FMX.Helpers.Android,//需要引入

14 Androidapi.JNI.Net,//需要引入

15 Androidapi.Helpers;//需要引入

16

17 type

18 TForm1 = class(TForm)19 Label1: TLabel;20 Button1: TButton;21 Memo1: TMemo;22 procedureButton1Click(Sender: TObject);23 private

24 {Private declarations}

25 public

26 {Public declarations}

27 end;28

29 var

30 Form1: TForm1;31

32 implementation

33

34 {$R *.fmx}

35 {$R *.NmXhdpiPh.fmx ANDROID}

36

37 //ip地址整数转字符串

38 function int2Ip(intIP : Int64) : string;39 var

40 n : int64;41 ip4, ip3, ip2, ip1: string;42 begin

43 Result := '';44 n := intIP shr 24;45 intIP := intIP xor (n shl 24);46 ip4 :=IntToStr(n);47

48 n := intIP shr 16;49 intIP := intIP xor (n shl 16);50 ip3 :=IntToStr(n);51

52 n := intIP shr 8;53 intIP := intIP xor (n shl 8);54 ip2 :=IntToStr(n);55

56 n :=intIP;57 ip1 :=IntToStr(n);58

59 Result := ip1 + '.' + ip2 + '.' + ip3 + '.' +ip4;60 end;61

62 //ip地址字符串转整数(没测过)

63 function ip2Int(const strIP : string): Int64;64 var

65 lst : TStringList;66 i : integer;67 begin

68 result := 0;69 lst := TStringList.Create;70 try

71 lst.Delimiter := '.';72 lst.DelimitedText :=strIP;73 for i := 0 to lst.Count - 1 do

74 result := result + StrToInt64(lst[i]) shl (24 - i * 8);75 finally

76 lst.Free;77 end;78 end;79

80 procedureTForm1.Button1Click(Sender: TObject);81 var

82 Service: JObject;83 WifiManager: JWifiManager;84 ConnectionInfo: JWifiInfo;85 ScanResults: JList;86 ScanResult: JScanResult;87 I: Integer;88 iIP: Int64;89 begin

90 Memo1.Lines.Clear;91 Service :=SharedActivity.getSystemService(TJContext.JavaClass.WIFI_SERVICE);92 WifiManager := TJWifiManager.Wrap((Service asILocalObject).GetObjectID);93 if not WifiManager.isWifiEnabled then

94 Memo1.Lines.Add('WiFi禁用')95 else

96 begin

97 ConnectionInfo :=WifiManager.getConnectionInfo;98 Memo1.Lines.Add('连接信息');99 Memo1.Lines.Add('SSID:' +JStringToString(ConnectionInfo.getSSID));100 Memo1.Lines.Add('BSSID:' +JStringToString(ConnectionInfo.getBSSID));101 Memo1.Lines.Add('IPV4:' +int2Ip(ConnectionInfo.getIpAddress));102 Memo1.Lines.Add('MAC address:' +JStringToString(ConnectionInfo.getMacAddress));103 ScanResults :=WifiManager.getScanResults;104 for I := 0 to ScanResults.size - 1 do

105 begin

106 Memo1.Lines.Add('');107 Memo1.Lines.Add('检测到的接入点' +IntToStr(I));108 ScanResult := TJScanResult.Wrap((ScanResults.get(I) asILocalObject).GetObjectID);109 Memo1.Lines.Add('SSID:' +JStringToString(ScanResult.SSID));110 Memo1.Lines.Add('BSSID:' +JStringToString(ScanResult.BSSID));111 Memo1.Lines.Add('Capabilities:' +JStringToString(ScanResult.capabilities));112 Memo1.Lines.Add('Frequency:' + IntToStr(ScanResult.frequency) + 'MHz');113 Memo1.Lines.Add('Signal level:' + IntToStr(ScanResult.level) + 'dBm');114 end

115 end;116 end;117

118 end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值