本文整理汇总了Java中android.net.NetworkInfo.isRoaming方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInfo.isRoaming方法的具体用法?Java NetworkInfo.isRoaming怎么用?Java NetworkInfo.isRoaming使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.NetworkInfo
的用法示例。
在下文中一共展示了NetworkInfo.isRoaming方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: haveInternet
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean haveInternet(Context context)
{
NetworkInfo info =
(NetworkInfo)((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null || !info.isConnected())
{
return false;
}
if (info.isRoaming())
{
// here is the roaming option you can change it if you want to
// disable internet while roaming, just return false
// 是否在漫游,可根据程序需求更改返回值
return false;
}
return true;
}
示例2: startMobilePairing
import android.net.NetworkInfo; //导入方法依赖的package包/类
public void startMobilePairing(String ipOrHostname, int port, boolean allowRoaming, Context c){
ConnectivityManager connMgr = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean wifiConnected = false;
boolean mobileConnected = false;
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()){
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) wifiConnected = true;
else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) mobileConnected = true;
boolean allowedToConnect = false;
// allowing mobile pairing even when connected to wifi because why not
if (wifiConnected){
allowedToConnect = true;
} else if (mobileConnected){
if (!networkInfo.isRoaming() || allowRoaming){
allowedToConnect = true;
} else {
notifyObservers(new PairingConnectionCallbackMessage(NOT_ALLOWED_TO_ROAM));
}
}
if (allowedToConnect){
pairingConnection = new TcpPairingConnection(ipOrHostname, port, c);
pairingConnection.addObserver(this);
new Thread(pairingConnection).start();
}
} else {
notifyObservers(new PairingConnectionCallbackMessage(NOT_CONNECTED));
}
}
示例3: sendToAllEnabledMobileServers
import android.net.NetworkInfo; //导入方法依赖的package包/类
static void sendToAllEnabledMobileServers(Notification n, Context c, List<MobileServer> enabledMobileServers){
ConnectivityManager connMgr = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
for(MobileServer mobileServer : enabledMobileServers){
if (!networkInfo.isRoaming() || mobileServer.isRoamingAllowed()){
ThreadPoolHandler.enqueueRunnable(new TcpNotificationConnection(c, n,
mobileServer.getCertificate(),
mobileServer.getIpOrHostname(),
mobileServer.getPortNumber()));
}
}
}
}
示例4: isRoaming
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isRoaming() {
try {
ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null) {
return netInfo.isRoaming();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return false;
}
示例5: getIsRoaming
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* Indicates whether the device is roaming on the currently active network. When true, it
* suggests that use of data may incur extra costs.
*/
@CalledByNative
private static boolean getIsRoaming(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) return false; // No active network.
return networkInfo.isRoaming();
}
示例6: isRoaming
import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
* returns true if the device uses roaming
*
* @param context
* @return
*/
public static boolean isRoaming(Context context) {
NetworkInfo networkInfo = getNetworkInfo(context);
if (networkInfo != null) {
return networkInfo.isRoaming();
}
return false;
}
示例7: isNotRoaming
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isNotRoaming(Context context) {
NetworkInfo info = getActiveNetworkInfo(getConnectivityManager(context));
return info != null && info.isConnected() && !info.isRoaming();
}
示例8: isConnectedRoaming
import android.net.NetworkInfo; //导入方法依赖的package包/类
public boolean isConnectedRoaming() {
final NetworkInfo info = getNetworkInfo();
return info != null && info.isConnected() && info.isRoaming() && info.getType() == ConnectivityManager.TYPE_MOBILE;
}
示例9: isValidMobileConnectionFor
import android.net.NetworkInfo; //导入方法依赖的package包/类
private boolean isValidMobileConnectionFor(NetworkInfo ni, String suffix) {
boolean valid_for_3g = getPreferenceBooleanValue("use_3g_" + suffix, false);
boolean valid_for_edge = getPreferenceBooleanValue("use_edge_" + suffix, false);
boolean valid_for_gprs = getPreferenceBooleanValue("use_gprs_" + suffix, false);
boolean valid_for_roaming = getPreferenceBooleanValue("use_roaming_" + suffix, true);
if(!valid_for_roaming && ni != null) {
if(ni.isRoaming()) {
return false;
}
}
if ((valid_for_3g || valid_for_edge || valid_for_gprs) &&
ni != null) {
int type = ni.getType();
// Any mobile network connected
if (ni.isConnected() &&
// Type 3,4,5 are other mobile data ways
(type == ConnectivityManager.TYPE_MOBILE || (type <= 5 && type >= 3))) {
int subType = ni.getSubtype();
// 3G (or better)
if (valid_for_3g &&
subType >= TelephonyManager.NETWORK_TYPE_UMTS) {
return true;
}
// GPRS (or unknown)
if (valid_for_gprs
&&
(subType == TelephonyManager.NETWORK_TYPE_GPRS || subType == TelephonyManager.NETWORK_TYPE_UNKNOWN)) {
return true;
}
// EDGE
if (valid_for_edge &&
subType == TelephonyManager.NETWORK_TYPE_EDGE) {
return true;
}
}
}
return false;
}
示例10: isRoaming
import android.net.NetworkInfo; //导入方法依赖的package包/类
public static boolean isRoaming(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
return (ni != null && ni.isRoaming());
}
示例11: updateNetworkState
import android.net.NetworkInfo; //导入方法依赖的package包/类
private void updateNetworkState(NetworkInfo info) {
boolean isConnected = mIsConnected;
boolean isFailover = mIsFailover;
boolean isCellularConnection = mIsCellularConnection;
boolean isRoaming = mIsRoaming;
boolean isAtLeast3G = mIsAtLeast3G;
if (null != info) {
mIsRoaming = info.isRoaming();
mIsFailover = info.isFailover();
mIsConnected = info.isConnected();
updateNetworkType(info.getType(), info.getSubtype());
} else {
mIsRoaming = false;
mIsFailover = false;
mIsConnected = false;
updateNetworkType(-1, -1);
}
mStateChanged = (mStateChanged || isConnected != mIsConnected
|| isFailover != mIsFailover
|| isCellularConnection != mIsCellularConnection
|| isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
if (Constants.LOGVV) {
if (mStateChanged) {
Log.v(LOG_TAG, "Network state changed: ");
Log.v(LOG_TAG, "Starting State: " +
(isConnected ? "Connected " : "Not Connected ") +
(isCellularConnection ? "Cellular " : "WiFi ") +
(isRoaming ? "Roaming " : "Local ") +
(isAtLeast3G ? "3G+ " : "<3G "));
Log.v(LOG_TAG, "Ending State: " +
(mIsConnected ? "Connected " : "Not Connected ") +
(mIsCellularConnection ? "Cellular " : "WiFi ") +
(mIsRoaming ? "Roaming " : "Local ") +
(mIsAtLeast3G ? "3G+ " : "<3G "));
if (isServiceRunning()) {
if (mIsRoaming) {
mStatus = STATUS_WAITING_FOR_NETWORK;
mControl = CONTROL_PAUSED;
} else if (mIsCellularConnection) {
DownloadsDB db = DownloadsDB.getDB(this);
int flags = db.getFlags();
if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
mStatus = STATUS_QUEUED_FOR_WIFI;
mControl = CONTROL_PAUSED;
}
}
}
}
}
}