ProgressDialog et etat du reseau.
Bonjour,
je développe une application qui a besoin d'avoir une connexion wifi.
Quand la connexion wifi est interrompue, il faut empêcher la saisie en mettant un ProgressDialog et le faire disparaitre quand la connexion wifi est revenue.
Or quand la connexion revient, mon ProgressDialog est toujours la alors que j'ai "dismiss" l'objet. Il n'est plus atteignable.
les ecouteurs
Code:
1 2 3 4 5
| wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// register the broadcast receiver for wifi state events
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
registerReceiver(wifiEventReceiver, filter); |
et la fonction en question.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
public void onReceive(Context Context, Intent intent) {
Intent stratIntent = new Intent( Context,BroadcastReceiver.class);
Context.startService(stratIntent);
int netID = 0;
String strBSSID = "";
wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String bssid = info.getSSID();
boolean disableAllOthers = true;
// a mettre en varaible admin ID_routeur
String ID_routeur = "Belkin.4614";
int count=0;
List<WifiConfiguration> lbssid = wifi.getConfiguredNetworks();
ProgressDialog pd_reseau2 = ProgressDialog.show(Elyx.this,
"Perte du reseau...", "Recherche", true );
pd_reseau2.hide();
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
if(info.getBSSID() == null){
//Toast.makeText(Elyx.this,"le réseau est perdu",Toast.LENGTH_SHORT).show();
pd_reseau2.show();
Toast.makeText(Elyx.this,"Show",Toast.LENGTH_SHORT).show();
launchWait();
}
else {
try {
pd_reseau2.hide();
} catch (Exception e){
Toast.makeText(Elyx.this,"Erreur = " + e.getMessage(),Toast.LENGTH_LONG).show();
}
Toast.makeText(Elyx.this,"Hide",Toast.LENGTH_SHORT).show();
//si nous somme actuellement connecter au bon routeur
if(bssid.equals(ID_routeur)){
try {
Toast.makeText(Elyx.this,"Connecté sur le reseau officiel.",Toast.LENGTH_LONG).show();
} catch (Exception e){
Toast.makeText(Elyx.this,"Erreur = " + e.getMessage(),Toast.LENGTH_LONG).show();
}
}
else
{
try {
Toast.makeText(Elyx.this,"HIDE differant",Toast.LENGTH_LONG).show();
} catch (Exception e){
Toast.makeText(Elyx.this,"Erreur = " + e.getMessage(),Toast.LENGTH_LONG).show();
}
// recherche l'id tu routeur wifi pi et le force dessus
while(lbssid.size()> count)
{
//mStrings.add(count,lbssid.get(count).SSID);
strBSSID = lbssid.get(count).SSID.replace("\"", "");
if(strBSSID.equals(ID_routeur)){
netID = lbssid.get(count).networkId;
}
count++;
}
wifi.enableNetwork(netID, disableAllOthers );
}
}
}
}
}; |