本文整理匯總了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;
}