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


Java ConnectivityManagerCompat类代码示例

本文整理汇总了Java中android.support.v4.net.ConnectivityManagerCompat的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityManagerCompat类的具体用法?Java ConnectivityManagerCompat怎么用?Java ConnectivityManagerCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectivityManagerCompat类属于android.support.v4.net包,在下文中一共展示了ConnectivityManagerCompat类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doRequestDownload

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
private Observable<Request> doRequestDownload(Integer requestCode) {
    return SafeObservable.fromNullCallable(() -> {
            if (getActivity() != null) {
                Request request = new Request();
                request.mRequestCode = requestCode;
                ConnectivityManager cm =  (ConnectivityManager) getActivity()
                        .getSystemService(Activity.CONNECTIVITY_SERVICE);
                NetworkInfo ni = cm.getActiveNetworkInfo();
                if (ni == null) {
                    request.mStatus = 1;
                    return request;
                }
                if (ConnectivityManagerCompat.isActiveNetworkMetered(cm) || ni.isRoaming()) {
                    request.mStatus = 2;
                    return request;
                }
                return request;
            }
            throw new IllegalStateException();
        })
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread());
}
 
开发者ID:jruesga,项目名称:rview,代码行数:25,代码来源:DownloadDialogFragment.java

示例2: getNetworkType

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
/**
 * Checks the network condition of the device and returns the best type. If the device
 * is connected to a WiFi and mobile network at the same time, then it would assume
 * that the connection is unmetered because of the WiFi connection.
 *
 * @param context Any context, e.g. the application context.
 * @return The current network type of the device.
 */
@NonNull
public static JobRequest.NetworkType getNetworkType(@NonNull Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        return JobRequest.NetworkType.ANY;
    }

    boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager);
    if (!metered) {
        return JobRequest.NetworkType.UNMETERED;
    }

    if (networkInfo.isRoaming()) {
        return JobRequest.NetworkType.CONNECTED;
    } else {
        return JobRequest.NetworkType.NOT_ROAMING;
    }
}
 
开发者ID:evernote,项目名称:android-job,代码行数:28,代码来源:Device.java

示例3: isConnectionMetered

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
@ReactMethod
public void isConnectionMetered(Promise promise) {
  if (mNoNetworkPermission) {
    promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE, null);
    return;
  }
  promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:9,代码来源:NetInfoModule.java

示例4: shouldUseLessTrafficData

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
public static boolean shouldUseLessTrafficData(Context context) {
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
		return false;
	}

	ConnectivityManager cm;
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
		cm = context.getSystemService(ConnectivityManager.class);
	} else {
		cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
	}
	// Checks if the device is on a metered network
	if (cm.isActiveNetworkMetered()) {
		// Checks user’s Data Saver settings.
		switch (ConnectivityManagerCompat.getRestrictBackgroundStatus(cm)) {
			case ConnectivityManagerCompat.RESTRICT_BACKGROUND_STATUS_ENABLED:
				// Background data usage is blocked for this app. Wherever possible,
				// the app should also use less data in the foreground.
				return true;
			case ConnectivityManagerCompat.RESTRICT_BACKGROUND_STATUS_WHITELISTED:
				// The app is whitelisted. Wherever possible,
				// the app should use less data in the foreground and background.
				return false;
			case ConnectivityManagerCompat.RESTRICT_BACKGROUND_STATUS_DISABLED:
				// Data Saver is disabled. Since the device is connected to a
				// metered network, the app should use less data wherever possible.
				return false;
		}
		return false;
	} else {
		// The device is not on a metered network.
		// Use data as required to perform syncs, downloads, and updates.
		return false;
	}
}
 
开发者ID:fython,项目名称:ImageGridView,代码行数:36,代码来源:NetworkUtils.java

示例5: shouldWaitForWifi

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
public static boolean shouldWaitForWifi()
{
  if ((FinskyApp.get().mInstallPolicies.hasMobileNetwork()) && (!((Boolean)FinskyPreferences.autoUpdateWifiOnly.get()).booleanValue())) {
    return false;
  }
  InstallPolicies localInstallPolicies = FinskyApp.get().mInstallPolicies;
  if (localInstallPolicies.isWifiNetwork())
  {
    int j;
    if (InstallPolicies.SUPPORTS_MOBILE_HOTSPOT) {
      if ((localInstallPolicies.isWifiNetwork()) && (localInstallPolicies.mConnectivityManager.isActiveNetworkMetered())) {
        j = 1;
      }
    }
    while (j == 0)
    {
      return false;
      j = 0;
      continue;
      j = 0;
    }
  }
  if (UiUtils.isAndroidTv())
  {
    if ((localInstallPolicies.hasNetwork()) && (!ConnectivityManagerCompat.isActiveNetworkMetered(localInstallPolicies.mConnectivityManager))) {}
    for (int i = 1; i != 0; i = 0) {
      return false;
    }
  }
  return true;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:32,代码来源:ReschedulerStrategy.java

示例6: updateNetworkStatus

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
private void updateNetworkStatus(Intent intent) {
    mIsNetworkMetered = ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager);

    if (intent == null) {
        final NetworkInfo activeNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo == null) {
            mIsNetworkConnected = false;
        } else {
            mIsNetworkConnected = activeNetworkInfo.isConnected();
        }
    } else {
        mIsNetworkConnected = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
    }
}
 
开发者ID:CzBiX,项目名称:v2ex-android,代码行数:15,代码来源:DeviceStatus.java

示例7: isMeteredNetwork

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
public static boolean isMeteredNetwork(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return (cm != null && ConnectivityManagerCompat.isActiveNetworkMetered(cm));
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:5,代码来源:Util.java

示例8: isOnMobile

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
public static boolean isOnMobile(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    return ConnectivityManagerCompat.isActiveNetworkMetered(cm);
}
 
开发者ID:M4lik,项目名称:burning-series,代码行数:7,代码来源:AndroidUtility.java

示例9: isConnectionMetered

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
public boolean isConnectionMetered() {
    if (mNoNetworkPermission) {
        return false;
    }
    return ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager);
}
 
开发者ID:CarGuo,项目名称:GSYVideoPlayer,代码行数:7,代码来源:NetInfoModule.java

示例10: getNetworkInfoFromBroadcast

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
@Nullable private NetworkInfo getNetworkInfoFromBroadcast(Context context, Intent intent) {
    return ConnectivityManagerCompat.getNetworkInfoFromBroadcast(getConnectivityManager(context), intent);
}
 
开发者ID:wikimedia,项目名称:apps-android-wikipedia,代码行数:4,代码来源:NetworkConnectivityReceiver.java

示例11: isActiveNetworkMetered

import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
/**
 * 对大数据传输时,需要调用该方法做出判断,如果流量敏感,应该提示用户
 * 
 * @param context
 * @return true表示流量敏感,false表示不敏感
 */
public static boolean isActiveNetworkMetered(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    return ConnectivityManagerCompat.isActiveNetworkMetered(cm);
}
 
开发者ID:LiuJunb,项目名称:Android-LSS,代码行数:12,代码来源:NetworkUtils.java


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