AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Android - delete WIFI

Ein Thema von danten · begonnen am 17. Jan 2018 · letzter Beitrag vom 7. Mär 2019
Antwort Antwort
Seite 1 von 2  1 2      
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#1

Android - delete WIFI

  Alt 17. Jan 2018, 08:25
Hello,
I need to delete all saved WIFI networks for business purposes and retrieve new ones from the list downloaded from the server.

Here the user would click on the WIFI network in the list and join only to her.

Thank you for your help.

Delphi-Quellcode:
procedure RemoveWifiList;
var
  WifiManagerObj: JObject;
  WifiManager: JWifiManager;
  ScanResult: JScanResult;
  i: Integer;
begin
  WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);

  for i := 0 to WifiManager.getScanResults.size do
  begin
    ScanResult := TJScanResult.Wrap((WifiManager.getScanResults.get(i) as ILocalObject).GetObjectID);
    WifiManager.removeNetwork(i);
  end;

end;

procedure ConnectToSelectedWIFI;
var
  WifiManager: JWifiManager;
  aSSID, aPASS: string;
  WifiConf: JWifiConfiguration;
begin
  WifiManager := ??????
  WifiConf := ?????

  aSSID := '"'+edSSID.Text+'"';
  aPASS := '"'+edPASS.Text+'"';

  WifiConf.SSID := StringToJString(aSSID);
  WifiConf.preSharedKey := StringToJString(aPASS);
  WifiConf.hiddenSSID := False;
  WIFIManager.addNetwork(WifiConf);
  WIFIManager.enableNetwork(WifiConf.networkId,True);
  ???? Create connections and connect new ???
end;
Daniel

Geändert von danten (17. Jan 2018 um 09:15 Uhr)
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#2

AW: Android - delete WIFI

  Alt 17. Jan 2018, 22:48
Nobody has help for me?
The procedure for removing the Wifi network works well on your mobile, but it does not work on your tablet.
Do you know why?
Thank you
Daniel
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
4.116 Beiträge
 
Delphi 12 Athens
 
#3

AW: Android - delete WIFI

  Alt 18. Jan 2018, 07:23
Not sure either, but maybe you have to work with WiFiConnection.

Rollo
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#4

AW: Android - delete WIFI

  Alt 18. Jan 2018, 08:12
Thank you for answer.
What is the programming language?
I can not C or C ++ and I do not understand the code.

Could not anyone put a code for Delphi?

I will be grateful.

Thank you
Daniel
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
4.116 Beiträge
 
Delphi 12 Athens
 
#5

AW: Android - delete WIFI

  Alt 18. Jan 2018, 09:10
This is probably Java.
Just replace the brackets { } by begin end and you're very close to Delphi anyhow
Should be OK to understand the basic procedures needed.

The basic steps are described there, you can try to find the similar classes in Delpi source.

Rollo
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#6

AW: Android - delete WIFI

  Alt 18. Jan 2018, 09:50
I probably do not understand it and nobody will correct my code.

Delphi-Quellcode:
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;
Daniel
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
4.116 Beiträge
 
Delphi 12 Athens
 
#7

AW: Android - delete WIFI

  Alt 18. Jan 2018, 10:00
Sorry, I have not time left and about to leave the office soon.
If you would have a complete test-project it would be easier to look at it.

Rollo
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#8

AW: Android - delete WIFI

  Alt 18. Jan 2018, 10:29
Thank you, I uploaded the project as an attachment.
Angehängte Dateien
Dateityp: 7z wifi.7z (243,3 KB, 20x aufgerufen)
Daniel
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#9

AW: Android - delete WIFI

  Alt 19. Jan 2018, 17:48
Hello, I have tried all the options according to the help but still do not have a functional application.

You really do not know why it does not work.

I set all permissions in permission and it does not work either.
Daniel
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
4.116 Beiträge
 
Delphi 12 Athens
 
#10

AW: Android - delete WIFI

  Alt 22. Jan 2018, 18:07
I found some time to check your demo.

Its hard to check, since I had to cleanup a lot.
I do not use UniDac, etc., so I have to separate some functions first,
and I tried to use with my fixed network ID here.

I assume your main goal is to connect with one network from the http list only, right ?

An my Nexus9 tablet I can move through the preconfigured network list, since I can see their SSID's (I removed saveConfiguration, to not destroy all my settings here).
But after removeNetwork it still connects to a removedSSID.

I'M not sure whether this behaviour is normal, but I lost a lot of time to unscramble the code, so I haven't test unter other settings.
The docs say this is depreceated anyway.
So all I can say now that I can walk through the networkID's, calling removeNewwork, but still my tablet keeps connected, and also will reconnect.


Delphi-Quellcode:
procedure TfrmApp.RemoveWifiList;
var
  WifiManagerObj: JObject;
  WifiManager: JWifiManager;
  ScanResult: JScanResult;
  List: JList;

  //WifiConf: JWifiConfiguration;
  i: Integer;
  netID: integer;
  LWifiConf: JWifiConfiguration;
  LSsid: String;
  LNetId: Integer;
begin
  try
  WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);

  Memo1.Lines.Insert(0, 'RemoveWifiList:');

  List := WifiManager.getConfiguredNetworks;

  for i := 0 to List.size -1 do
  begin

    LWifiConf := TJWifiConfiguration.Wrap( List.get(i) );
    LSsid := JStringToString( LWifiConf.SSID );
    LNetId := LWifiConf.networkId;

    Memo1.Lines.Insert(0, '- SSID: ' + LSsid + ' ID(' + LNetId.ToString + ') REMOVED');

    WifiManager.removeNetwork( LNetId );
// WifiManager.saveConfiguration(); // TEST this is maybe missing to store permanently


  end;
  except
    on E: exception do
    begin
      ShowMessage('Remove: '+E.Message);
    end;
  end;

...

end;

Rollo
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz