Transfer: Delphi Get Android Phone WIFI Information (XE8)

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 & lt .fmx } // IP address Integer String 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 address string to integer (not tested) 
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');
    endendend
  
; 
 
 
end . 
———————————————— 
Copyright Statement: This article is an original article by CSDN blogger "Decode Liu Yongfeng", following the CC 4.0 BY- SA copyright agreement, please attach the original text Source link and this statement. 
Original link: https: // blog.csdn.net/lyf_lyf/java/article/details/48169575

 

Guess you like

Origin www.cnblogs.com/timba1322/p/12681581.html