当前位置:首页 » 网络管理 » android判断wifi
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

android判断wifi

发布时间: 2023-05-15 03:35:57

A. android 能判断当前网络是否连接,连接的是 wifi 还是 3g/4g

// 获取代表联网状态的NetWorkInfo对象 NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
// 获取当前的网络连接是否可用 if (null == networkInfo){Toast.makeText(this, "当前的网络连接不可用", Toast.LENGTH_SHORT).show();
//当网络不可用时,跳转到网络设置页面 startActivityForResult(new Intent(
android.provider.Settings.ACTION_WIRELESS_SETTINGS), 1);} else {boolean available = networkInfo.isAvailable();
if (available){Log.i("通知", "当前的网络连接可用");
Toast.makeText(this, "当前的网络连接可用", Toast.LENGTH_SHORT).show();} else {Log.i("通知", "销友当前的网络连接不可用");
Toast.makeText(this, "当前的网络连接不可用", Toast.LENGTH_SHORT).show();}}State state = connManager.getNetworkInfo(
ConnectivityManager.TYPE_MOBILE).getState();
if (State.CONNECTED == state){Log.i("通知", "GPRS网络已连接");
Toast.makeText(this, "GPRS网络已连接", Toast.LENGTH_SHORT).show();}state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
if (State.CONNECTED == state){Log.i("通知", "WIFI网络已连接");
Toast.makeText(this, "WIFI网络已连接", Toast.LENGTH_SHORT).show();}//// 跳转到无线网亏键槐络设置界面
// startActivity(new
// Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
//// 跳转到无限wifi网络设置界面
// startActivity(new
// Intent(android.provider.Settings.ACTION_WIFI_SETTINGS)); }也可以:
privatevoid testConnectivityManager(){ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//mobile 3G Network State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
Log.d(mobile.toString());
//wifi Network State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
Log.d(wifi.toString());
//如果3G网络和wifi网络都未连接,且不是处于正在连接状态 则进入Network Setting界面 由用户亮源配置网络连接if(mobile==State.CONNECTED||mobile==State.CONNECTING)return;if(wifi==State.CONNECTED||wifi==State.CONNECTING)return;startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));//进入无线网络配置界面
//startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //进入手机中的wifi网络设置界面 }

B. android开发怎么判断wifi信号强度

通过WifiManager的方法getScanResults()获取List<ScanResult>的集合,ScanResult.level就是信号强度是个负数,然后使用
WifiManager.calculateSignalLevel(scanResult.level,
100);就可得到确定的信号强度(calculateSignalLevel为计算信号等级函数,MAX_RSSI和MIN_RSSI分别为最强和最弱信号强度等级的信号强度阀值)。

C. android 判断当前的网络连接是wifi还是3g,4g csdn

/**
* 判断是否是wifi连接
*/
public static boolean isWifi(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null)
return false;
return connectivity.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;

}
/**
* 判断网络是否连接
*
*/
public static boolean isConnected(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (null != connectivity) {
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (null != info && info.isConnected()) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}

D. 如何检查Android中的WiFi网络是否连接成功

01.public boolean isWifiConnect() {
02. ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
03. NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
04. return mWifi.isConnected();
05. }
代码非常简单,纳粗档洞乱操作也非常简单。

01.boolean isConnected;
02.isConnected = isWifiConnect();
03.if (isConnected == false) {
04.Toast toast = Toast.makeText(Sync.this, "Wifi is NOT connected yet", Toast.LENGTH_SHORT);
05.toast.setGravity(Gravity.CENTER, 0, 0);
06.toast.show();
07.} else {
08.Toast toast = Toast.makeText(Sync.this, "Wifi is connected yet"凳备, Toast.LENGTH_SHORT);
09.toast.setGravity(Gravity.CENTER, 0, 0);
10.toast.show();
11.}

E. Android判断wifi是5G还是2.4G

所谓5G wifi是指运行在5Ghz 高频段上的第五代wifi技术,采用802.11ac协议标准。 无线联网技术发展至今已经进入到第五代,举帆我们现在普遍使用的是运行在2.4Ghz上的无线技术,还是采用的辩扮(第四代)802.11n标准。 我们如正灶雹果拿高速公路来比喻5GHz的WiFi频段,那么 802.11n标准会是奔驰汽车,而802.11ac标准会是更上一层楼,可以理解为跑车,传输速率是802.11n的3倍。 所以只有采用802.11ac标准,运行在5Ghz上频段上的wifi才能真正发挥第五代wifi技术的威力。

F. 在android上查看wifi状态,代码如下:

不知道你的程序报的是什么错,给你一个例子吧,不过方法和你的有点差别:
public class WifiAdmin {
/**WiFi Manager**/
private WifiManager wifimanager;
/**WiFi Information**/
private WifiInfo wifiinfo;
/**Activity NetWork List**/
private List<ScanResult> netlist;
/**Configured NetWork List**/
private List<WifiConfiguration> connectedlist;
/**WiFi Lock**/
private WifiLock wifilock;

public WifiAdmin(Context context) {
wifimanager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
}

/**
* WiFi Operate
* */
/**Open WiFi**/
public void openWifi() {
if (!wifimanager.isWifiEnabled()) {
wifimanager.setWifiEnabled(true);
}
}
/**Close WiFi**/
public void closeWifi() {
if (wifimanager.isWifiEnabled()) {
wifimanager.setWifiEnabled(false);
}
}
/**WiFi State**/
public int checkState() {
return wifimanager.getWifiState();
}

/**
* WiFiLock Operate
* */
/**Create WiFiLock**/
public void creatWifiLock() {
wifilock = wifimanager.createWifiLock("Test");
}
/**Lock WiFi**/
public void acquireWifiLock() {
wifilock.acquire();
}
/**Clear WiFiLock**/
public void releaseWifiLock() {
if (wifilock.isHeld()) {
wifilock.release();
}
}
/**
* WiFiInfo Operate
* */
/**Get WiFiInfo**/
public WifiInfo getWifiInfo(){
wifiinfo = wifimanager.getConnectionInfo();
return wifiinfo;
}

/**
* NetWork Operate
* */
/**Scan**/
public void startScan() {
wifimanager.startScan();
netlist = wifimanager.getScanResults();
connectedlist = wifimanager.getConfiguredNetworks();
}
/**Get Configured NetWork**/
public List<WifiConfiguration> getConfiguration() {
return connectedlist;
}
/**Get Activity NetWork**/
public List<ScanResult> getWifiList() {
return netlist;
}
/**Connect a NetWork**/
public void connectConfiguration(int index) {
if (index < 0 || index > connectedlist.size()) {
return;
}
wifimanager.enableNetwork(connectedlist.get(index).networkId,true);
}
/**Add a NetWork**/
public void addNetwork(WifiConfiguration wcg) {
int wcgID = wifimanager.addNetwork(wcg);
wifimanager.enableNetwork(wcgID, true);
}
/**DisConnect a NetWork**/
public void disconnectWifi(int netId) {
wifimanager.disableNetwork(netId);
wifimanager.disconnect();
}
}

G. Android 判断网络是否可用以及网络类型(WIFI,2G,3G,4G)

最后附上一个简易的轮询方法检测网络状态

H. Android判断是Wifi还是4G网络代码

为大家分享了Android判断是Wifi还是4G网络的具体肆缓帆代码,供大家参考,具体内容如下
package com.chengxinet.bobo.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;

/**
* Created by Administrator on 2016/1/7.
*/
public class NetworkUtils {
public static boolean isNetworkAvailable(Context c) {
Context context = c.getApplicationContext();
/裂雹/ 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

if (connectivityManager == null) {
return false;
} else {
// 获取NetworkInfo对象
NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();

if (networkInfo != null && networkInfo.length > 0) {
for (NetworkInfo aNetworkInfo : networkInfo) {
// System.out.println(i + "===状态===" + networkInfo[i].getState());
// System.out.println(i + "===类型===" + networkInfo[i].getTypeName());
// 判断当前网络状态是否为连接状态
if (aNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}

/**
* 判断WIFI是否打开
* @param context
* @return
*/
public static boolean isWifiEnabled(Context context) {
ConnectivityManager mgrConn = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mgrTel = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return ((mgrConn.getActiveNetworkInfo() != null && mgrConn
.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel
.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}

/**
* 判断是否是3G网络哪缓
* @param context
* @return
*/
public static boolean is3rd(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkINfo = cm.getActiveNetworkInfo();
if (networkINfo != null
&& networkINfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
return false;
}

/**
* 判断是wifi还是3g网络
* @param context
* @return
*/
public static boolean isWifi(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkINfo = cm.getActiveNetworkInfo();
if (networkINfo != null
&& networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
return false;
}
}

I. Android判断wifi是5G还是2.4G

某些系统的安卓会在誉链5G信号后面有个5G的表示,如果没有标示,点开已经连上的wifi信号,灶段看连接速度,一般300Mbps以上的都庆辩孙是5G

J. android 判断wifi是否有密码

您好,是否有wifi密码你点击一下就知道,有密码的wifi点击后会弹出密码框,填写密码后才可以进行颂瞎连接州肢使用的。
中国电信提供最优质的网络通讯服务,目前安徽电信有活动,话费1折扣,9元打99元,野迹空建议直接通过安徽电信营业厅或者实体营业厅查询。