本文整理汇总了Java中android.net.NetworkInfo.isAvailable方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInfo.isAvailable方法的具体用法?Java NetworkInfo.isAvailable怎么用?Java NetworkInfo.isAvailable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.NetworkInfo
的用法示例。
在下文中一共展示了NetworkInfo.isAvailable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.net.NetworkInfo; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if(!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){
return;
}
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) return;
if (networkInfo.isAvailable()& networkInfo.isConnected()) {
if (networkInfo.getType()==ConnectivityManager.TYPE_WIFI) {
ipAddress = getWifiIpAddress(context);
Log.d(TAG, "WIFI "+ipAddress);
} else if (networkInfo.getType()==ConnectivityManager.TYPE_MOBILE) {
ipAddress = getMobileIpAddress();
Log.d(TAG,"MOBILE "+ipAddress);
}
}
}
示例2: isNetworkOnline
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 检查网络是否在线
*/
public static boolean isNetworkOnline(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && (netInfo.isConnectedOrConnecting() || netInfo.isAvailable())) {
return true;
}
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
} else {
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
}
} catch (Exception e) {
return false;
}
return false;
}
示例3: onReceive
import android.net.NetworkInfo; //导入方法依赖的package包/类
public void onReceive(Context arg0, Intent intent) {
if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
this.connectivityManager = (ConnectivityManager) MQConversationActivity.this
.getSystemService("connectivity");
NetworkInfo info = this.connectivityManager.getActiveNetworkInfo();
if (this.isFirstReceiveBroadcast) {
this.isFirstReceiveBroadcast = false;
} else if (info == null || !info.isAvailable()) {
MQConversationActivity.this.changeTitleToNetErrorState();
} else {
MQConversationActivity.this.mCurrentAgent = MQConversationActivity.this
.mController.getCurrentAgent();
MQConversationActivity.this.changeTitleToAgentName(MQConversationActivity
.this.mCurrentAgent);
}
}
}
示例4: isNetworkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 判断是否有网络连接
*
* @param context
* @return
*/
public static boolean isNetworkConnected(Context context) {
if (context != null) {
// 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// 获取NetworkInfo对象
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
//判断NetworkInfo对象是否为空
if (networkInfo != null)
return networkInfo.isAvailable();
}
return false;
}
示例5: isWifiAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 判断WiFi是否可用
*
* @param context Context
* @return 表示网络可用
*/
public static boolean isWifiAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo info = connectivity.getActiveNetworkInfo();
return info != null && info.getType() == ConnectivityManager.TYPE_WIFI
&& info.isAvailable();
}
return false;
}
示例6: isWifiAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 判断是否有可用状态的Wifi,以下情况返回false:
* 1. 设备wifi开关关掉;
* 2. 已经打开飞行模式;
* 3. 设备所在区域没有信号覆盖;
* 4. 设备在漫游区域,且关闭了网络漫游。
*
* @return boolean wifi为可用状态(不一定成功连接,即Connected)true
*/
public static boolean isWifiAvailable(Context context) {
NetworkInfo[] nets = getConnectivityManager(context).getAllNetworkInfo();
if (nets != null) {
for (NetworkInfo net : nets) {
if (net.getType() == ConnectivityManager.TYPE_WIFI) { return net.isAvailable(); }
}
}
return false;
}
示例7: getNetworkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static int getNetworkType(Context mContext) {
ConnectivityManager manager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager == null) {
return -1;
}
NetworkInfo networkinfo = manager.getActiveNetworkInfo();
if (networkinfo == null || !networkinfo.isConnected() || !networkinfo.isAvailable()) {
return -1;
}
return networkinfo.getType();
}
示例8: isNetworkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isNetworkConnected(Context context) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.getState()== NetworkInfo.State.CONNECTED && mNetworkInfo.isAvailable();
}
return false;
}
示例9: getAvailableNetworkInfo
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static NetworkInfo getAvailableNetworkInfo(Context context) {
NetworkInfo ni = null;
try {
ni = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
} catch (Exception e) {
e.printStackTrace();
}
return (ni == null || !ni.isAvailable()) ? null : ni;
}
示例10: isNetworkAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* check NetworkAvailable
* @return
*/
public static boolean isNetworkAvailable() {
ConnectivityManager manager = (ConnectivityManager) ContextHolder.getContext().getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
if (null == manager)
return false;
NetworkInfo info = manager.getActiveNetworkInfo();
if (null == info || !info.isAvailable())
return false;
return true;
}
示例11: 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;
}
示例12: getAvailableNetWorkInfo
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static NetworkInfo getAvailableNetWorkInfo(Context context) {
try {
NetworkInfo activeNetInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
if (activeNetInfo == null || !activeNetInfo.isAvailable()) {
return null;
}
return activeNetInfo;
} catch (Exception e) {
e.printStackTrace();
DebugLog.log(TAG, e.getMessage());
return null;
}
}
示例13: networkChecker
import android.net.NetworkInfo; //导入方法依赖的package包/类
@Singleton
@Provides
NetworkChecker networkChecker(LoriApp app) {
return () -> {
ConnectivityManager internetManager = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = internetManager.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected() && networkInfo.isAvailable() && networkInfo.isConnectedOrConnecting();
};
}
示例14: isNetworkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 只关注是否联网
*/
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
示例15: isNetAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isNetAvailable(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isAvailable();
}