本文整理汇总了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;
}
}
示例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();
}
}
}
示例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();
}
示例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!");
}
}
示例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;
}
示例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();
}
示例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;
}