本文整理匯總了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();
}