当前位置: 首页>>代码示例>>Java>>正文


Java NetworkInfo.isAvailable方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:x-falcon,项目名称:Virtual-Hosts,代码行数:19,代码来源:NetworkReceiver.java

示例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;
}
 
开发者ID:nickyangjun,项目名称:EasyEmoji,代码行数:27,代码来源:CommonUtil.java

示例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);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:MQConversationActivity.java

示例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;
}
 
开发者ID:Mrqinlei,项目名称:ImitateZHRB,代码行数:19,代码来源:NetworkUtils.java

示例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;
}
 
开发者ID:flyminiboy,项目名称:EasyOKHttp,代码行数:17,代码来源:NetUtil.java

示例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;
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:19,代码来源:Network.java

示例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();
}
 
开发者ID:bigjelly,项目名称:AndFast,代码行数:13,代码来源:NetworkUtils.java

示例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;
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:9,代码来源:CommonUtils.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:10,代码来源:Utils.java

示例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;
}
 
开发者ID:yzzslow0,项目名称:Ec2m,代码行数:15,代码来源:NetUtil.java

示例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;
}
 
开发者ID:bigjelly,项目名称:AndFast,代码行数:14,代码来源:NetworkUtils.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:LetvUtil.java

示例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();
    };
}
 
开发者ID:zmeiko,项目名称:LoriApp,代码行数:10,代码来源:AppModule.java

示例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;
}
 
开发者ID:haihaio,项目名称:AmenWeather,代码行数:15,代码来源:Util.java

示例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();
}
 
开发者ID:Yuanhongliang,项目名称:HLOLI,代码行数:6,代码来源:NetworkUtil.java


注:本文中的android.net.NetworkInfo.isAvailable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。