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


Java ConnectivityManager.isActiveNetworkMetered方法代码示例

本文整理汇总了Java中android.net.ConnectivityManager.isActiveNetworkMetered方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityManager.isActiveNetworkMetered方法的具体用法?Java ConnectivityManager.isActiveNetworkMetered怎么用?Java ConnectivityManager.isActiveNetworkMetered使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.ConnectivityManager的用法示例。


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

示例1: getNetworkState

import android.net.ConnectivityManager; //导入方法依赖的package包/类
/**
 * Gets the state of internet availability, whether there is no connection at all,
 * whether the connection has no usage limit (like most WiFi), or whether this is
 * a metered connection like most cellular plans or hotspot WiFi connections.
 */
private static int getNetworkState(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork == null || !activeNetwork.isConnected()) {
        return FLAG_NET_UNAVAILABLE;
    }

    int networkType = activeNetwork.getType();
    switch (networkType) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
            if (Build.VERSION.SDK_INT >= 16 && cm.isActiveNetworkMetered()) {
                return FLAG_NET_METERED;
            } else {
                return FLAG_NET_NO_LIMIT;
            }
        default:
            return FLAG_NET_METERED;
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:27,代码来源:UpdateService.java

示例2: onCreate

import android.net.ConnectivityManager; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ((TextView) findViewById(R.id.text)).setCompoundDrawablesWithIntrinsicBounds(
                getDrawable(R.drawable.ic_action_name),
                null,
                null,
                null
        );

        ConnectivityManager c = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        c.isActiveNetworkMetered();

//        createConfigurationContext(getResources().getConfiguration());
    }
 
开发者ID:evant,项目名称:silent-support,代码行数:18,代码来源:MainActivity.java

示例3: isUnmeteredNetworkConnected

import android.net.ConnectivityManager; //导入方法依赖的package包/类
@SuppressLint({"NewApi"})
public boolean isUnmeteredNetworkConnected() {
    ConnectivityManager connectivityManager = (ConnectivityManager) HttpService.this.getApplicationContext().getSystemService("connectivity");
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetworkInfo != null) {
        if (activeNetworkInfo.getType() == 1) {
            return true;
        }
        if (VERSION.SDK_INT >= 16) {
            return !connectivityManager.isActiveNetworkMetered();
        }
    }
    return false;
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:15,代码来源:HttpService.java

示例4: mayPrerender

import android.net.ConnectivityManager; //导入方法依赖的package包/类
private boolean mayPrerender(CustomTabsSessionToken session) {
    if (!DeviceClassManager.enablePrerendering()) return false;
    // TODO(yusufo): The check for prerender in PrivacyManager now checks for the network
    // connection type as well, we should either change that or add another check for custom
    // tabs. Then PrivacyManager should be used to make the below check.
    if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) return false;
    if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return false;
    ConnectivityManager cm =
            (ConnectivityManager) mApplication.getApplicationContext().getSystemService(
                    Context.CONNECTIVITY_SERVICE);
    return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSession(session);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:13,代码来源:CustomTabsConnection.java

示例5: isUnmetered

import android.net.ConnectivityManager; //导入方法依赖的package包/类
public static boolean isUnmetered(Context context) {
    ConnectivityManager manager = getConnectivityManager(context);
    NetworkInfo info = getActiveNetworkInfo(manager);
    return info != null && info.isConnected() && !manager.isActiveNetworkMetered();
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:6,代码来源:DeviceUtils.java

示例6: isMetered

import android.net.ConnectivityManager; //导入方法依赖的package包/类
public static boolean isMetered(Context context) {
    ConnectivityManager manager = getConnectivityManager(context);
    NetworkInfo info = getActiveNetworkInfo(manager);
    return info != null && info.isConnected() && manager.isActiveNetworkMetered();
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:6,代码来源:DeviceUtils.java

示例7: isActiveNetworkMetered

import android.net.ConnectivityManager; //导入方法依赖的package包/类
static boolean isActiveNetworkMetered(Context context) {
    if (sIsNetworkListenerDisabled) return sIsNetworkMetered;
    ConnectivityManager cm =
            (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.isActiveNetworkMetered();
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:7,代码来源:DownloadManagerService.java

示例8: uploadStream

import android.net.ConnectivityManager; //导入方法依赖的package包/类
private static String uploadStream(MainActivity context, InputStream is, String RequestURL, String name, final String filename) throws IOException {
    String BOUNDARY = UUID.randomUUID().toString();

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isMetered = cm.isActiveNetworkMetered();
    if (isMetered) {
        if (prepareDialog) {
            askForMeteredConn(context);
            if (regardlessOfMeteredConnection) {
                prepareDialog = false;
            }
        }
        if (!regardlessOfMeteredConnection) {
            throw new IOException("canceled due to metered connection");
        }
    }

    URL url = new URL(RequestURL);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(READ_TIME_OUT);
    conn.setConnectTimeout(CONNECT_TIME_OUT);
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setUseCaches(false);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Charset", CHARSET);
    conn.setRequestProperty("Connection", "keep-alive");
    conn.setRequestProperty("Content-Type", CONTENT_TYPE + "; boundary=" + BOUNDARY);
    OutputStream outputSteam = conn.getOutputStream();
    DataOutputStream dos = new DataOutputStream(outputSteam);
    String sb = PREFIX +
            BOUNDARY + LINE_END +
            "Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + filename + "\"" + LINE_END +
            "Content-Type: application/octet-stream; charset=" + CHARSET + LINE_END +
            LINE_END;
    dos.write(sb.getBytes());
    byte[] bytes = new byte[1024];
    int len;
    while ((len = is.read(bytes)) != -1) {
        dos.write(bytes, 0, len);
    }
    is.close();
    dos.write(LINE_END.getBytes());
    byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINE_END).getBytes();
    dos.write(end_data);
    dos.flush();
    int res = conn.getResponseCode();
    if (res == 200) return conn.getResponseMessage();
    throw new IOException("response code: " + res);
}
 
开发者ID:LionNatsu,项目名称:takephoto,代码行数:51,代码来源:HttpHelper.java

示例9: isActiveNetworkMetered

import android.net.ConnectivityManager; //导入方法依赖的package包/类
public static boolean isActiveNetworkMetered(ConnectivityManager cm) {
    return cm.isActiveNetworkMetered();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:ConnectivityManagerCompatJellyBean.java


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