procedure TfrmApp.ConnectToWifi;
// ERROR
var
WifiManagerObj: JObject;
WifiManager: JWifiManager;
WifiConfiguration: JWifiConfiguration;
i: integer;
netID: integer;
List: JList;
begin
try
aSSID := '
"'+qDB.FieldByName('
ssid').AsString+'
"';
aPass := '
"'+qDB.FieldByname('
pass').AsString+'
"';
WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
WifiManager := TJWifiManager.Wrap((WifiManagerObj
as ILocalObject).GetObjectID);
WifiConfiguration.SSID := StringToJString(aSSID);
WifiConfiguration.preSharedKey := StringToJString(aPass);
List := WifiManager.getConfiguredNetworks;
for i := 0
to List.size -1
do
begin
if WifiConfiguration.SSID = stringToJString(aSSID)
then
begin
netID := WifiManager.addNetwork(WifiConfiguration);
WifiManager.disconnect;
WifiManager.enableNetwork(netID, True);
WifiManager.reconnect;
Break;
end;
end;
except
on E:
exception do
begin
ShowMessage('
Connect: '+E.
Message);
end;
end;
end;
procedure TfrmApp.RemoveWifiList;
// NOT WORK IN TABLET AND ANDROID 7
var
WifiManagerObj: JObject;
WifiManager,WifiManager2: JWifiManager;
ScanResult: JScanResult;
WifiConf: JWifiConfiguration;
i,r: Integer;
netID: integer;
begin
try
WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
WifiManager := TJWifiManager.Wrap((WifiManagerObj
as ILocalObject).GetObjectID);
try
for i := 0
to WifiManager.getScanResults.size -1
do
begin
ScanResult := TJScanResult.Wrap((WifiManager.getScanResults.get(i)
as ILocalObject).GetObjectID);
netID := WifiManager.getConnectionInfo.getNetworkId;
WifiManager.removeNetwork(netID);
WifiManager.saveConfiguration();
end;
finally
ConnectToWifi;
end;
except
on E:
exception do
begin
ShowMessage('
Remove: '+E.
Message);
end;
end;
end;