Java tutorial
//package com.java2s; import android.content.Context; import android.net.wifi.WifiManager; public class Main { private static WifiManager wifiManager; private static WifiManager.MulticastLock multicastLock; private static WifiManager.WifiLock wifiLock; public static void lockWifi(Context context, String lockStr) { if (wifiManager == null) { wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); multicastLock = wifiManager.createMulticastLock(lockStr + "multicast_lock"); multicastLock.acquire(); wifiLock = wifiManager.createWifiLock(lockStr + "wifi_lock"); wifiLock.acquire(); } } }