本文整理汇总了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;
}
}
示例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());
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例9: isActiveNetworkMetered
import android.net.ConnectivityManager; //导入方法依赖的package包/类
public static boolean isActiveNetworkMetered(ConnectivityManager cm) {
return cm.isActiveNetworkMetered();
}