当前位置: 首页>>代码示例>>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;未经允许,请勿转载。