本文整理了Java中android.net.wifi.WifiManager.isWifiEnabled()
方法的一些代码示例,展示了WifiManager.isWifiEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.isWifiEnabled()
方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:isWifiEnabled
暂无
代码示例来源:origin: stackoverflow.com
private boolean checkWifiOnAndConnected() {
WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifiMgr.isWifiEnabled()) { // Wi-Fi adapter is ON
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
if( wifiInfo.getNetworkId() == -1 ){
return false; // Not connected to an access point
}
return true; // Connected to an access point
}
else {
return false; // Wi-Fi adapter is OFF
}
}
代码示例来源:origin: stackoverflow.com
if (wifi.isWifiEnabled() == false)
代码示例来源:origin: facebook/facebook-android-sdk
@Override
public void initAndCheckEligibility() throws ScannerException {
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
throw new ScannerException(ScannerException.Type.NOT_SUPPORTED);
}
if (!Validate.hasWiFiPermission(context)) {
throw new ScannerException(ScannerException.Type.PERMISSION_DENIED);
}
if (wifiManager == null) {
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
}
boolean isWifiScanningAlwaysOn = isWifiScanningAlwaysOn();
if (!isWifiScanningAlwaysOn && !wifiManager.isWifiEnabled()) {
throw new ScannerException(ScannerException.Type.DISABLED);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void isWifiEnabled_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted()
throws Exception {
shadowOf(wifiManager).setAccessWifiStatePermission(false);
try {
wifiManager.isWifiEnabled();
fail("SecurityException not thrown");
} catch (SecurityException e) {
// expected
}
}
代码示例来源:origin: cSploit/android
if(!mWifiManager.isWifiEnabled()){
mStatusText.setText( getString(R.string.wifi_activating_iface) );
mWifiManager.setWifiEnabled(true);
代码示例来源:origin: mayubao/KuaiChuan
/**
* 判断wifi是否开启的状态
* @return
*/
public boolean isWifiEnable(){
return mWifiManager == null ? false : mWifiManager.isWifiEnabled();
}
代码示例来源:origin: mayubao/KuaiChuan
/**
* 关闭wifi
*/
public void closeWifi(){
if(mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(false);
}
}
代码示例来源:origin: mayubao/KuaiChuan
/**
* 打开wifi
*/
public void openWifi(){
if(!mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(true);
}
}
代码示例来源:origin: multidots/android-app-common-tasks
public static void onWifi(Context mContext, String action) {
WifiManager wm = ((WifiManager) mContext
.getSystemService(Context.WIFI_SERVICE));
if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("on")) {
if (!wm.isWifiEnabled()) {
wm.setWifiEnabled(true);
}
}
if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("off")) {
if (wm.isWifiEnabled()) {
wm.setWifiEnabled(false);
}
}
}
代码示例来源:origin: multidots/android-app-common-tasks
public static void onWifi(Context mContext, String action) {
WifiManager wm = ((WifiManager) mContext
.getSystemService(Context.WIFI_SERVICE));
if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("on")) {
if (!wm.isWifiEnabled()) {
wm.setWifiEnabled(true);
}
}
if (action.toLowerCase(Locale.getDefault()).equalsIgnoreCase("off")) {
if (wm.isWifiEnabled()) {
wm.setWifiEnabled(false);
}
}
}
代码示例来源:origin: stackoverflow.com
public String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (manager.isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
代码示例来源:origin: stackoverflow.com
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()) {
// WIFI ALREADY ENABLED. GRAB THE MAC ADDRESS HERE
WifiInfo info = wifiManager.getConnectionInfo();
String address = info.getMacAddress();
} else {
// ENABLE THE WIFI FIRST
wifiManager.setWifiEnabled(true);
// WIFI IS NOW ENABLED. GRAB THE MAC ADDRESS HERE
WifiInfo info = wifiManager.getConnectionInfo();
String address = info.getMacAddress();
}
代码示例来源:origin: multidots/android-app-common-tasks
if (wm.isWifiEnabled()) {
btnWifiOnOff.setText("Wifi on");
isWifi = false;
代码示例来源:origin: jberkel/sms-backup-plus
@SuppressWarnings("deprecation")
private boolean isConnectedViaWifi_pre_SDK21() {
WifiManager wifiManager = getWifiManager();
return (wifiManager != null &&
wifiManager.isWifiEnabled() &&
getConnectivityManager().getNetworkInfo(TYPE_WIFI) != null &&
getConnectivityManager().getNetworkInfo(TYPE_WIFI).isConnected());
}
代码示例来源:origin: mayubao/KuaiChuan
/**
* 关闭当前的Wifi网络
* @return
*/
public boolean disconnectCurrentNetwork(){
if(mWifiManager != null && mWifiManager.isWifiEnabled()){
int netId = mWifiManager.getConnectionInfo().getNetworkId();
mWifiManager.disableNetwork(netId);
return mWifiManager.disconnect();
}
return false;
}
代码示例来源:origin: palaima/DebugDrawer
wifi.setChecked(wifiManager.isWifiEnabled());
wifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer
private void enableWiFi() {
try {
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
}
} catch (Exception e) {
// critical error: do not die
}
}
代码示例来源:origin: stackoverflow.com
private WifiManager wifiManager;
@Override
public void onCreate(Bundle bund) {
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()){
wifiManager.setWifiEnabled(false);
}else{
wifiManager.setWifiEnabled(true);
}
}
代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer
private void withWiFiManager() {
when(wifiManager.isWifiEnabled()).thenReturn(false);
when(wifiManager.startScan()).thenReturn(true);
when(wifiManager.getScanResults()).thenReturn(scanResults);
when(wifiManager.getConnectionInfo()).thenReturn(wifiInfo);
when(wifiManager.getConfiguredNetworks()).thenReturn(configuredNetworks);
}
代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer
private void verifyWiFiManager() {
verify(wifiManager).isWifiEnabled();
verify(wifiManager).setWifiEnabled(true);
verify(wifiManager).startScan();
verify(wifiManager).getScanResults();
verify(wifiManager).getConnectionInfo();
verify(wifiManager).getConfiguredNetworks();
}
内容来源于网络,如有侵权,请联系作者删除!