Back to project page intent_radio.
The source code is released under:
Copyright (c) 2014 Stephen Blott Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Soft...
If you think the Android project intent_radio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.smblott.intentradio; /*from w w w . j a v a 2 s . co m*/ import android.content.Context; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.WifiLock; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class WifiLocker extends Logger { private static WifiLock lock = null; private static WifiManager manager = null; public static void lock(Context context, String app_name) { if ( manager == null ) manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if ( manager != null && lock == null ) lock = manager.createWifiLock(WifiManager.WIFI_MODE_FULL, app_name); if ( lock == null ) return; if ( ! Connectivity.onWifi() ) { unlock(); return; } if ( lock.isHeld() ) return; log("Wifi lock: acquired"); lock.acquire(); } public static void unlock() { if ( lock != null && lock.isHeld() ) { log("Wifi lock: released"); lock.release(); } } }