網路上查了很多 取得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;
跟XE6 7 不同的是
原本是uses Androidapi.JNI.Net.Wifi
現在改為 Androidapi.JNI.Net 亂改測試出來的...
接下來 實際RUN 會跳一個錯誤
neither user nor current process has android permission device_power
看起來像是沒有權限
這個實在是 用英文找也看不董
要去project option裡面設定
這樣就能取得Wifi資訊了
留言列表