當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。