I use this code to activate or deactivate the tethering hotspot so other devices can use the Internet data of my device. It used to work well but it is not working anymore for Nougat, do you have any hint? thanks.
This is the code I use:
private boolean ActivateTethering(boolean bEstate)
{ WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] methods = wifiManager.getClass().getDeclaredMethods();
for(Method method : methods)
{ if(method.getName().equals("setWifiApEnabled"))
{ try
{ if(bEstate == true)
{ wifiManager.setWifiEnabled(false); //Turning off wifi because tethering requires wifi to be off
method.invoke(wifiManager, null, true); //Activating tethering
return true;
}
else
{ method.invoke(wifiManager, null, false); //Deactivating tethering
return true;
}
}
catch(Exception e)
{ return false;
}
}
}
//Error setWifiApEnabled not found
return false;
}
I get the error java.lang.reflect.InvocationTargetException