• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Difference in several ways to toggle WIFI tethering

bnwgraaf

Lurker
My car can connect to my phones WIFI hotspot.

Unfortunatelly, everytime I start the car, I have to (re)connect. During driving, the connection is kept nicely.

The strange thing is, that after starting the car, the entertainment system does not connect automatically, but I discovered the next thing after starting the car (and with that the entertainment system):
If I turn off and on the WIFI hotspot through the Android ROMs tiles, the connection is made automatically.
If I turn off and on the WIFI hotspot with a toggle widget or a profile scheduler, than it will not connect.
Instead I get a DHCP error, if I try to connect...

So my question is, is there a difference if you toggle WIFI hotspot with the tiles or with code?

I have tried several profile task apps, with no success. I have used an own written (copied) peace of code, also with no success. I used this peace of code:
Java:
import android.content.*;
import android.net.wifi.*;
import java.lang.reflect.*;
/**
* Created by B.Graaf on 20/10/2016.
*/
public class WifiApSwitch {

        //check whether wifi hotspot on or off
        public static boolean isApOn(Context context) {
            WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
            try {
                Method method = wifimanager.getClass().getDeclaredMethod("isWifiApEnabled");
                method.setAccessible(true);
                return (Boolean) method.invoke(wifimanager);
            }
            catch (Throwable ignored) {}
            return false;
        }

        // toggle wifi hotspot on or off
        public static boolean configApState(Context context) {
            WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
            WifiConfiguration wificonfiguration = null;
            try {
                // if WiFi is on, turn it off
                if(isApOn(context)) {
                    wifimanager.setWifiEnabled(false);
                }
                Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
                method.invoke(wifimanager, wificonfiguration, !isApOn(context));
                return true;
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }
    } // end of class
 
Back
Top Bottom