本文整理汇总了Java中android.net.NetworkInfo.isConnectedOrConnecting方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInfo.isConnectedOrConnecting方法的具体用法?Java NetworkInfo.isConnectedOrConnecting怎么用?Java NetworkInfo.isConnectedOrConnecting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.NetworkInfo
的用法示例。
在下文中一共展示了NetworkInfo.isConnectedOrConnecting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: haveInternet
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean haveInternet(Context context) {
//Obtem o gerenciador de conectividade do sistema
ConnectivityManager lConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//Obtem a informação de rede
NetworkInfo lNetworkInfo = lConnectivityManager.getActiveNetworkInfo();
//Retorna se está conectado ou não
return lNetworkInfo != null && lNetworkInfo.isConnectedOrConnecting();
}
示例2: isConnecting
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isConnecting(Context mContext) {
ConnectivityManager manager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager == null) {
return false;
}
NetworkInfo networkinfo = manager.getActiveNetworkInfo();
if (networkinfo == null || !networkinfo.isAvailable()
|| !networkinfo.isConnectedOrConnecting()) {
return false;
}
return true;
}
示例3: IsNetworkAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
public boolean IsNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) {
return false;
}
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
示例4: isThereInternetConnection
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Checks if the device has any active internet connection.
*
* @return true device with internet connection, otherwise false.
*/
private boolean isThereInternetConnection() {
boolean isConnected;
ConnectivityManager connectivityManager =
(ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting());
return isConnected;
}
示例5: isConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isConnected() {
ConnectivityManager cm = (ConnectivityManager) MyApplication.getInstance().getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null
&& activeNetwork.isConnectedOrConnecting();
}
示例6: isOnline
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isOnline(Context context) {
try {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo != null) {
return activeNetworkInfo.isConnectedOrConnecting();
}
return false;
} catch (Exception e) {
return true;
}
}
示例7: isConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isConnected(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = null;
if (connectivityManager != null) {
networkInfo = connectivityManager.getActiveNetworkInfo();
}
return networkInfo != null && networkInfo.isConnectedOrConnecting();
}
示例8: checkConnection
import android.net.NetworkInfo; //导入方法依赖的package包/类
public boolean checkConnection(){ //method for checking network connection
ConnectivityManager cm =
(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
return isConnected;
}
示例9: isNetworkAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Check for internet connection
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
示例10: updateFromPreferences
import android.net.NetworkInfo; //导入方法依赖的package包/类
public void updateFromPreferences(SharedPreferences prefs) {
// in case server url has changed reconnect
if (mServerURL == null || !mServerURL.equalsIgnoreCase(prefs.getString("pref_url", ""))) {
mServerURL = prefs.getString("pref_url", "");
close();
}
ConnectivityManager cm = (ConnectivityManager) mCtx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) {
connect();
} else {
close();
}
}
示例11: isConnectedOrConnecting
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 判断有无网络正在连接中(查找网络、校验、获取IP等)。
*
* @return boolean 不管wifi,还是mobile net,只有当前在连接状态(可有效传输数据)才返回true,反之false。
*/
public static boolean isConnectedOrConnecting(Context context) {
NetworkInfo[] nets = getConnectivityManager(context).getAllNetworkInfo();
if (nets != null) {
for (NetworkInfo net : nets) {
if (net.isConnectedOrConnecting()) { return true; }
}
}
return false;
}
示例12: getCurrentNetState
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* get the net state of current
* @param context the context.
* @return the state code. see {@linkplain #STATE_2G} and etc.
*/
public static byte getCurrentNetState(Context context) {
byte code = STATE_NO;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni != null && ni.isConnectedOrConnecting()) {
switch (ni.getType()) {
//wifi
case ConnectivityManager.TYPE_WIFI:
code = STATE_WIFI;
break;
//mobile 网络
case ConnectivityManager.TYPE_MOBILE:
switch (ni.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_GPRS: //联通2g
case TelephonyManager.NETWORK_TYPE_CDMA: //电信2g
case TelephonyManager.NETWORK_TYPE_EDGE: //移动2g
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
code = STATE_2G;
break;
case TelephonyManager.NETWORK_TYPE_EVDO_A: //电信3g
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
code = STATE_3G;
break;
case TelephonyManager.NETWORK_TYPE_LTE://4G
code = STATE_4G;
break;
default:
code = STATE_UNKNOWN;
}
break;
default:
code = STATE_UNKNOWN;
}
}
return code;
}
示例13: isNetworkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isNetworkConnected(Context context) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
示例14: isNetworkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
return ni != null && ni.isConnectedOrConnecting();
}
示例15: isNetworkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
private boolean isNetworkConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
return ni != null && ni.isConnectedOrConnecting();
}