本文整理汇总了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());
}
示例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;
}
}
示例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));
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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));
}
示例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);
}
示例9: isConnectionMetered
import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
public boolean isConnectionMetered() {
if (mNoNetworkPermission) {
return false;
}
return ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager);
}
示例10: getNetworkInfoFromBroadcast
import android.support.v4.net.ConnectivityManagerCompat; //导入依赖的package包/类
@Nullable private NetworkInfo getNetworkInfoFromBroadcast(Context context, Intent intent) {
return ConnectivityManagerCompat.getNetworkInfoFromBroadcast(getConnectivityManager(context), intent);
}
示例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);
}