From de738691db03ff61bf292b75bfa716b75fe34af1 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 14 May 2023 22:08:48 +0200 Subject: delay start of proxy service on network change --- app/java/src/WifiListenerReceiver.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/java/src/WifiListenerReceiver.java b/app/java/src/WifiListenerReceiver.java index e8ebedf..ca22965 100644 --- a/app/java/src/WifiListenerReceiver.java +++ b/app/java/src/WifiListenerReceiver.java @@ -11,6 +11,7 @@ import android.net.wifi.WifiManager; import android.net.wifi.WifiInfo; import android.os.Bundle; +import android.os.Handler; import android.util.Log; @@ -23,12 +24,18 @@ public class WifiListenerReceiver extends BroadcastReceiver // start if (networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) { - WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - WifiInfo wifiInfo = wifiManager.getConnectionInfo(); - - // if (wifiInfo.getSSID() == setting.get(LOCAL_HOME_WIFI_SSID)) - - context.startService(dnsProxyService.setAction(DNSProxyService.ACTION_START)); + // wait a few moments for wifi to be fully there + (new Handler()).postDelayed(new Runnable() { + @Override + public void run() { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + + // if (wifiInfo.getSSID() == setting.get(LOCAL_HOME_WIFI_SSID)) + + context.startService(dnsProxyService.setAction(DNSProxyService.ACTION_START)); + } + }, 1000); } // stop -- cgit v1.2.3