Friday, 6 October 2017

Delphi XE10 取得android Wifi資訊

[转]http://kamilia1470.pixnet.net/blog/post/199762657-delphi-xe10-%E5%8F%96%E5%BE%97android-wifi%E8%B3%87%E8%A8%8A

網路上查了很多 取得Wifi資訊的方式
但都是XE6 XE7
Code丟到XE10都不能用
以下是XE10測試成功的Code
uses Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNIBridge,
  Androidapi.JNI.GraphicsContentViewText,Androidapi.JNI.Net;
procedure TForm2.FormCreate(Sender: TObject);
var
  Service: JObject;
  WifiManager: JWifiManager;
  ConnectionInfo: JWifiInfo;
  ScanResults: JList;
  ScanResult: JScanResult;
  I: Integer;
begin
  Memo.Lines.Clear;
  Service := SharedActivity.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  WifiManager := TJWifiManager.Wrap((Service as ILocalObject).GetObjectID);
  if not WifiManager.isWifiEnabled then
    Memo.Lines.Add('Wifi is disabled')
  else
  begin
    ConnectionInfo := WifiManager.getConnectionInfo;
    Memo.Lines.Add('Connection info');
    Memo.Lines.Add('  SSID: ' + JStringToString(ConnectionInfo.getSSID));
    Memo.Lines.Add('  BSSID: ' + JStringToString(ConnectionInfo.getBSSID));
    Memo.Lines.Add('  MAC address: ' + JStringToString(ConnectionInfo.getMacAddress));
    ScanResults := WifiManager.getScanResults;
    for I := 0 to ScanResults.size - 1 do
    begin
      Memo.Lines.Add('');
      Memo.Lines.Add('Detected access point ' + IntToStr(I));
      ScanResult := TJScanResult.Wrap((ScanResults.get(I) as ILocalObject).GetObjectID);
      Memo.Lines.Add('  SSID: ' + JStringToString(ScanResult.SSID));
      Memo.Lines.Add('  BSSID: ' + JStringToString(ScanResult.BSSID));
      Memo.Lines.Add('  Capabilities: ' + JStringToString(ScanResult.capabilities));
      Memo.Lines.Add('  Frequency: ' + IntToStr(ScanResult.frequency) + 'MHz');
      Memo.Lines.Add('  Signal level: ' + IntToStr(ScanResult.level) + 'dBm');
    end
  end
end

No comments:

Post a Comment

zomok E-commerce system plan. Choose your online ordering system. No-risk 30 day free trial. Then USD 9/month. No credit card required.

zomok E-commerce system plan. Choose your online ordering system. No-risk 30 day free trial. Then USD 9/month. No credit card required. h...