Back to project page WifiHotspotBTEnabler.
The source code is released under:
GNU General Public License
If you think the Android project WifiHotspotBTEnabler 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 ca.diogosoares.android.utilities; /*from w w w . jav a2 s . c om*/ import java.util.ArrayList; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.wifi.WifiManager; import ca.diogosoares.android.listeners.WifiUtilitiesListener; /** * * Require permissions for : * android.permission.ACCESS_WIFI_STATE * android.permission.CHANGE_WIFI_STATE * * @author Diogo Soares, 02/2014 */ public class WifiUtilities { private ArrayList<WifiUtilitiesListener> mListeners = null; private int mState = WifiManager.WIFI_STATE_DISABLED; private int mPreviousState = WifiManager.WIFI_STATE_DISABLED; private int mPreviousFinalState = WifiManager.WIFI_STATE_DISABLED; // Disabled or Enabled only private Context mContext = null; private IntentFilter mIntentFilter = null; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { mState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); mPreviousState = intent.getIntExtra(WifiManager.EXTRA_PREVIOUS_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); if (mPreviousState==WifiManager.WIFI_STATE_DISABLED || mPreviousState==WifiManager.WIFI_STATE_ENABLED) mPreviousFinalState = mPreviousState; for(WifiUtilitiesListener listener:mListeners) listener.onWifiStateChanged(); } } }; public WifiUtilities(Context context) { this.mContext = context; mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); mContext.registerReceiver(mReceiver, mIntentFilter); mListeners = new ArrayList<WifiUtilitiesListener>(); } public void setListener(WifiUtilitiesListener listener) { this.mListeners.add(listener); } public void removeListener(WifiUtilitiesListener listener) { this.mListeners.remove(listener); } public void setEnableWifiHotspot(boolean enable) { WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(enable); } public int getState() { return this.mState; } public int getPreviousState() { return this.mPreviousState; } public int getPreviousFinalState() { return this.mPreviousFinalState; } public static String getWifiStateString(int state) { switch (state) { case WifiManager.WIFI_STATE_DISABLED: return "Disabled"; case WifiManager.WIFI_STATE_DISABLING: return "Disabling"; case WifiManager.WIFI_STATE_ENABLED: return "Enabled"; case WifiManager.WIFI_STATE_ENABLING: return "Enabling"; default: return "Unknown"; } } }