Delphi 获取安卓手机WIFI信息(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 *.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.

相关阅读 >>

Delphi的控制台程式添加图标

Delphi 将svg加载到timage控件

Delphi 7 中dbgrid的排序

Delphi 搭配hotkeyedit控件来解决问题

Delphi xe6 firemonkey移动应用程序获取android设备屏幕信息

Delphi的cpu调试窗口

Delphi 防止刷新时闪烁的终极解决办法

Delphi playsound(); 停止播放

Delphi在pagecontrol1上面的分页动态创建edit组件

Delphi强制刷新注册表方法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...