當前位置: 首頁>>代碼示例>>Java>>正文


Java WifiManager.getWifiState方法代碼示例

本文整理匯總了Java中android.net.wifi.WifiManager.getWifiState方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.getWifiState方法的具體用法?Java WifiManager.getWifiState怎麽用?Java WifiManager.getWifiState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.getWifiState方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isWifiEnabled

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static boolean isWifiEnabled() {
    Context myContext = Globals.getContext();
    if (myContext == null) {
        throw new NullPointerException("Global context is null");
    }
    WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE);
    if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
        ConnectivityManager connManager = (ConnectivityManager) myContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiInfo = connManager
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        return wifiInfo.isConnected();
    } else {
        return false;
    }
}
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:17,代碼來源:S_MVP.java

示例2: onHandleIntent

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
protected void onHandleIntent(Intent intent) {
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST);
    if (intent == null) {
        Utils.debugLog(TAG, "received null Intent, ignoring");
        return;
    }
    Utils.debugLog(TAG, "WiFi change service started, clearing info about wifi state until we have figured it out again.");
    NetworkInfo ni = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    int wifiState = wifiManager.getWifiState();
    if (ni == null || ni.isConnected()) {
        Utils.debugLog(TAG, "ni == " + ni + "  wifiState == " + printWifiState(wifiState));
        if (wifiState == WifiManager.WIFI_STATE_ENABLED
                || wifiState == WifiManager.WIFI_STATE_DISABLING  // might be switching to hotspot
                || wifiState == WifiManager.WIFI_STATE_DISABLED   // might be hotspot
                || wifiState == WifiManager.WIFI_STATE_UNKNOWN) { // might be hotspot
            if (wifiInfoThread != null) {
                wifiInfoThread.interrupt();
            }
            wifiInfoThread = new WifiInfoThread();
            wifiInfoThread.start();
        }
    }
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:26,代碼來源:WifiStateChangeService.java

示例3: getWifiState

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static int getWifiState(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService("wifi");
    if (wifi == null) {
        return 4;
    }
    return wifi.getWifiState();
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:8,代碼來源:NetworkHelper.java

示例4: getWifiState

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 獲取Wifi的狀態,需要ACCESS_WIFI_STATE權限
 *
 * @param context 上下文
 * @return 取值為WifiManager中的WIFI_STATE_ENABLED、WIFI_STATE_ENABLING、WIFI_STATE_DISABLED、WIFI_STATE_DISABLING、WIFI_STATE_UNKNOWN之一
 * @throws Exception 沒有找到wifi設備
 */
public static int getWifiState(Context context) throws Exception {
    WifiManager wifiManager = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE));
    if (wifiManager != null) {
        return wifiManager.getWifiState();
    }
    else {
        throw new Exception("wifi device not found!");
    }
}
 
開發者ID:liying2008,項目名稱:Simpler,代碼行數:17,代碼來源:NetWorkUtils.java

示例5: isWifiOpen

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static boolean isWifiOpen(Context context) {
    WifiManager wifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    int state = wifiManager.getWifiState();
    boolean flag = false;
    if (state == WifiManager.WIFI_STATE_ENABLED
            || state == WifiManager.WIFI_STATE_ENABLING) {
        flag = true;
    }
    return flag;
}
 
開發者ID:kamisakihideyoshi,項目名稱:TaipeiTechRefined,代碼行數:12,代碼來源:WifiUtility.java

示例6: onCreate

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the stored sort order
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    int sortOrderOrdinal = prefs.getInt(PREF_WIFI_SORT_ORDER, SortOrder
            .NONE.ordinal());
    if (sortOrderOrdinal >= 0 && sortOrderOrdinal < SortOrder.values()
            .length) {
        sortOrder = SortOrder.values()[sortOrderOrdinal];
    }

    // Make a BroadcastReceiver to get the scan results
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final WifiManager wifi = (WifiManager) getSystemService
                    (Context.WIFI_SERVICE);
            int state = wifi.getWifiState();
            if (state != WifiManager.WIFI_STATE_ENABLED) {
                Utils.errMsg(WifiActivity.this, "WiFi is not enabled");
                return;
            }
            List<ScanResult> scanResults = wifi.getScanResults();
            // Make the ArrayList
            mNetworks = new ArrayList<WifiNetwork>(scanResults.size());
            for (ScanResult scanResult : scanResults) {
                mNetworks.add(new WifiNetwork(scanResult));
            }
            // Sort the arrays list
            Collections.sort(mNetworks);
            // Set the adapter
            mNetworkListdapter = new NetworkListAdapter();
            setListAdapter(mNetworkListdapter);
        }
    };
    registerReceiver(mReceiver, new IntentFilter(
            WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));


    // Call refresh to set the contents
    refresh();
}
 
開發者ID:KennethEvans,項目名稱:Misc,代碼行數:46,代碼來源:WifiActivity.java

示例7: checkWifiState

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static boolean checkWifiState(Context context) {
    WifiManager wifiManger = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiManger.getWifiState()==WifiManager.WIFI_STATE_ENABLED;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:5,代碼來源:WifiUtil.java


注:本文中的android.net.wifi.WifiManager.getWifiState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。