Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to enable/disable wifi or internet

// for android Q and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            Intent panelIntent = new 
Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
            startActivityForResult(panelIntent, 0);
        } else {
            // for previous android version
            WifiManager wifiManager = (WifiManager) 
this.getApplicationContext().getSystemService(WIFI_SERVICE);
            wifiManager.setWifiEnabled(true);
        }
        in AndroidManifest file
//
 <uses-permission
    android:name="android.permission.CHANGE_WIFI_STATE"
    android:required="true" />
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #wifi #internet
ADD COMMENT
Topic
Name
2+3 =