您好,登錄后才能下訂單哦!
項目用到,標記記錄一下方便下一次使用。
先獲取系統服務
(ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE);
注冊廣播
IntentFilter ifilter = new IntentFilter( WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); ifilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); ifilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); mContext.registerReceiver(mWifiStateReceiver, ifilter);
接收廣播
public class WifiStateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { AspLog.v(TAG, "WifiStateReceiver onReceive:" + intent.getAction()); if (intent.getAction().equals( WifiManager.WIFI_STATE_CHANGED_ACTION)) { if (dialog_loading != null) { AspLog.v(TAG, "WIFI_STATE_CHANGED_ACTION dialog_loading=" + dialog_loading + ",showing=" + dialog_loading.isShowing() + ",wifistate=" + getWIFIstate()); } else { AspLog.v(TAG, "WIFI_STATE_CHANGED_ACTION dialog_loading=" + dialog_loading + ",showing=null" + ",wifistate=" + getWIFIstate()); } if (dialog_loading != null && dialog_loading.isShowing() && getWIFIstate() == State.CONNECTED) { dialog_loading.dismiss(); finishAsOk(intent); } } if (intent.getAction().equals( WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {// 判斷wifi // enable的事件 if (mWifiList == null || mWifiList.size() == 0) { mWifiList = mWifiManager.getScanResults(); listScanResults(); } handlerWIFIMessage(STATE_UPDATE_LIST); } if (intent.getAction().equals( WifiManager.NETWORK_STATE_CHANGED_ACTION)) {// 判斷wifi // enable的事件 mWifiList = mWifiManager.getScanResults(); listScanResults(); AspLog.v(TAG, "wifiList size:" + mWifiList.size()); handlerWIFIMessage(STATE_UPDATE_LIST); if (dialog_loading != null) { AspLog.v(TAG, "NETWORK_STATE_CHANGED_ACTION dialog_loading=" + dialog_loading + ",showing=" + dialog_loading.isShowing() + ",wifistate=" + getWIFIstate()); } else { AspLog.v(TAG, "NETWORK_STATE_CHANGED_ACTION dialog_loading=" + dialog_loading + ",showing= null" + ",wifistate=" + getWIFIstate()); } if (dialog_loading != null && dialog_loading.isShowing() && getWIFIstate() == State.CONNECTED) { dialog_loading.dismiss(); finishAsOk(intent); } } } catch (Exception ex) { ex.printStackTrace(); } } }
更多的移動互聯網的發展趨勢、app開發、移動互聯網應用相關的資料請到互聯網的一點事:www.yidin.net 留言
android QQ群:222392467
資料:
http://www.yidin.net/?p=8280
http://www.yidin.net/?p=9725
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。