Android執行個體-擷取安卓手機WIFI資訊(XE8+小米2)

來源:互聯網
上載者:User

標籤:

 

結果:

1.必須開啟Access wifi state許可權,不開啟許可權會出圖二的錯誤。

 

相關資料:

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

 

執行個體代碼:

  1 unit Unit1;  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     procedure Button1Click(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 procedure TForm1.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 as ILocalObject).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 do105     begin106       Memo1.Lines.Add(‘‘);107       Memo1.Lines.Add(‘檢測到的存取點 ‘ + IntToStr(I));108       ScanResult := TJScanResult.Wrap((ScanResults.get(I) as ILocalObject).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     end115   end;116 end;117 118 end.

 

Android執行個體-擷取安卓手機WIFI資訊(XE8+小米2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.