直播系统定制,判断数据连接是否可用

2020-10-23 17:52:51 浏览数 (1)

代码语言:javascript复制
/**
     * 判断数据连接是否可用
     *
     * @param context
     * @return
     */
    public static boolean isNetworkAvailable(Context context) {
        try {
            ConnectivityManager manager = (ConnectivityManager) NetworkUtils.getSystemService(context,
                    Context.CONNECTIVITY_SERVICE);
            if (manager != null) {
                NetworkInfo[] networkInfos = manager.getAllNetworkInfo();
                if (networkInfos != null) {
                    for (NetworkInfo networkInfo : networkInfos) {
                        if (networkInfo != null && networkInfo.isConnected()) {
                            return true;
                        }
                    }
                }
            }
        } catch (Exception e) {
        }
        return false;
    }

以上就是 直播系统定制,判断数据连接是否可用的相关代码,更多内容欢迎关注之后的文章

0 人点赞