Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.net.wifi.WifiManager;

public class Main {
    public static void toggleWifi(Context context) {
        WifiManager wifi_manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wifi_manager != null) {
            switch (wifi_manager.getWifiState()) {
            case WifiManager.WIFI_STATE_DISABLED:
                wifi_manager.setWifiEnabled(true);
                break;
            case WifiManager.WIFI_STATE_ENABLED:
                wifi_manager.setWifiEnabled(false);
                break;
            }
        }
    }
}