Ich verbinde mich mit einem Wifi-Netzwerk in meiner App und während ich das tue, zeige ich einem Benutzer einen Kostüm-Dialog, der Animation darin hat.wifi Manager wifiManager.addNetwork Stoppt meine UI
Problem ist, dass, während ich diese Linie tun>
wifiManager.addNetwork(conf);
meine Animation in der stecken und manchmal meine App Dialog get geht reagiert nicht.
eine Idee, wie das zu beheben?
und wenn ich einen Dialog während der Verbindung mit einem Netzwerk nicht zeigen kann, was schlagen Sie vor, einen Benutzer zu zeigen?
das ist mein Connect-Funktion in meinem Wifi Wrapper-Klasse-Netzwerk:
public void connectToNetwork(String ssidName, String netPassword, final Context applicationContext, final wifiConnectionEsteblishedInterface callback) { // in order to call callback from another thread it needs to be final
final String networkSSID = ssidName;
String networkPass = netPassword;
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String should contain
conf.preSharedKey = "\"" + networkPass + "\"";
WifiManager wifiManager = (WifiManager) applicationContext.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
Log.d("myLogs", "log-0");
callback.callbackFromWifi(); // calls the cllback
}
und das ist mein Dialog Zuhörer
public void onClick(DialogInterface dialog, int id) { //on button clicked
mainDialog.show(); //show main dialog back again
loaderScreenMainText.setText("Connecting to RADWIN WiFi"); // shows on screen message
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Do something after 5s = 5000ms
wifiWrapper WifiWrapper = new wifiWrapper();
WifiWrapper.toggleWiFi(Scanning_Barcode_Activity.this, true); // turns wifi ON
aligmentManager aligmentManager = new aligmentManager(); // tells the manager that we started looking for a wifi
aligmentManager.initlizedConnectingToWifi();
if (scanResults != null) { //in future use we will use scanResults veriable which is already initlized by now;
WifiWrapper.connectToNetwork("nmsRoom", "12345678", getApplication(), callbackFunctionForisWifiConnection); //in the future we will pass the scan results to the network
//
} else {
//do something in case scan result fails
}
}
}, 500); //deley in order to start the animation before hand (otherwise the dialog shows after, 2, 3 seconds
}
Thnx Allot, @Panel kennen Sie einen einfacheren Weg, dann öffnen Sie eine AsyncTask, um den Wifi-Betrieb zu machen? –
Sie können einen neuen Thread starten, run() überschreiben und dort Ihren Code kopieren. Vergiss nicht, start() darauf zu setzen. – Panel
THNX half es zuzuteilen –