TAGS :Viewed: 6 - Published at: a few seconds ago

[ How to enable mobile data or wifi without going to wireless settings page ]

I am able to determine users network avaibility and if it is not available I show a dialog telling them to go to settings to enable internet.

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

Can I enable the wifi settings without going to wifi settings activity?

Answer 1

 WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

       wifi.setWifiEnabled(false);//Turn off Wifi

        wifi.setWifiEnabled(true);//Turn on Wifi

should Work and dot forgot to add below permission.

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />