本文整理汇总了Java中android.net.NetworkInfo.isConnected方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInfo.isConnected方法的具体用法?Java NetworkInfo.isConnected怎么用?Java NetworkInfo.isConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.NetworkInfo
的用法示例。
在下文中一共展示了NetworkInfo.isConnected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNetworkTypeName
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
}
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
String proxyHost = android.net.Proxy.getDefaultHost();
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
: NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
示例2: isNetworkAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isNetworkAvailable() {
try {
ConnectivityManager connectivity = (ConnectivityManager) AppManager.app().getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (info != null && info.isConnected()) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}
示例3: getNetWorkType
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* get the network type (wifi,wap,2g,3g)
*
* @param context
* @return
*/
public static int getNetWorkType(Context context) {
int mNetWorkType = NETWORKTYPE_INVALID;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
String type = networkInfo.getTypeName();
if (type.equalsIgnoreCase("WIFI")) {
mNetWorkType = NETWORKTYPE_WIFI;
} else if (type.equalsIgnoreCase("MOBILE")) {
String proxyHost = android.net.Proxy.getDefaultHost();
mNetWorkType = TextUtils.isEmpty(proxyHost)
? (isFastMobileNetwork(context) ? NETWORKTYPE_3G : NETWORKTYPE_2G)
: NETWORKTYPE_WAP;
}
} else {
mNetWorkType = NETWORKTYPE_INVALID;
}
return mNetWorkType;
}
示例4: isConnectingToInternet
import android.net.NetworkInfo; //导入方法依赖的package包/类
public boolean isConnectingToInternet(){
ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
NetworkInfo mWifi = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWifi.isConnected()) {
return true;
}
}
return false;
}
示例5: isNetworkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* 判断网络是否连通
*/
public static boolean isNetworkConnected(Context context) {
try {
if(context!=null){
@SuppressWarnings("static-access")
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && info.isConnected();
}else{
/**如果context为空,就返回false,表示网络未连接*/
return false;
}
}catch (Exception e){
e.printStackTrace();
return false;
}
}
示例6: netIsConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean netIsConnected(Context context) {
ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//手机网络连接状态
NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
//WIFI连接状态
NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
//当前无可用的网络
return false;
}
return true;
}
示例7: isNetworkAvailable
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Determina se internet è attivo
*/
public static boolean isNetworkAvailable(Context c) {
ConnectivityManager connectivityManager
= (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
示例8: check3Gwifi
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean check3Gwifi(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo infoM = manager.getNetworkInfo(0);
if (manager.getNetworkInfo(1).isConnected() || infoM.isConnected()) {
return true;
}
return false;
}
示例9: getConnectionInfo
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Get the latest network connection information
*
* @param info the current active network info
* @return a JSONObject that represents the network info
*/
private JSONObject getConnectionInfo(NetworkInfo info) {
String type = TYPE_NONE;
String extraInfo = "";
if (info != null) {
// If we are not connected to any network set type to none
if (!info.isConnected()) {
type = TYPE_NONE;
}
else {
type = getType(info);
}
extraInfo = info.getExtraInfo();
}
LOG.d(LOG_TAG, "Connection Type: " + type);
LOG.d(LOG_TAG, "Connection Extra Info: " + extraInfo);
JSONObject connectionInfo = new JSONObject();
try {
connectionInfo.put("type", type);
connectionInfo.put("extraInfo", extraInfo);
} catch (JSONException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
}
return connectionInfo;
}
示例10: isDeviceOnline
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Checks whether the device currently has a network connection.
*
* @return true if the device has a network connection, false otherwise.
*/
private boolean isDeviceOnline() {
ConnectivityManager connMgr =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
return (networkInfo != null && networkInfo.isConnected());
}
示例11: isOnline
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* @return true if the internet connection currently in use is functional,
* otherwise false
*/
public static boolean isOnline(final Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnected();
}
示例12: isConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
public boolean isConnected(Context context){
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
return true;
else
return false;
}
示例13: isNetWorkConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* check if network avalable
*
* @param context
* @return
*/
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() && mNetworkInfo.isConnected();
}
}
return false;
}
示例14: networkIsConnected
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Get the state of networking connection of the current mobile
* @return the network is connected in mobile or not
*/
public static boolean networkIsConnected(Context context){
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo =
connectivityManager.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
}
示例15: isDeviceOnline
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Check internet connectivity.
*
* @return true if device is connect to <b>any</b> network, false otherwise.
*/
private boolean isDeviceOnline(Context ctx) {
ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && info.isConnected();
}