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元,野跡空建議直接通過安徽電信營業廳或者實體營業廳查詢。