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


Java NetworkInfo.isRoaming方法代码示例

本文整理汇总了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;
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:19,代码来源:MIP_NetworkUtils.java

示例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));
    }
}
 
开发者ID:rootkiwi,项目名称:an2linuxclient,代码行数:36,代码来源:PairingConnectionHandler.java

示例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()));
            }
        }
    }
}
 
开发者ID:rootkiwi,项目名称:an2linuxclient,代码行数:15,代码来源:NotificationConnectionHandler.java

示例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;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:13,代码来源:ConnectionsManager.java

示例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();
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:13,代码来源:AndroidNetworkLibrary.java

示例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;

}
 
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:15,代码来源:HelperFunctions.java

示例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();
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:5,代码来源:DeviceUtils.java

示例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;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:5,代码来源:MediaNetworkRequirement.java

示例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;
    }
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:46,代码来源:PreferencesProviderWrapper.java

示例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());
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:6,代码来源:Util.java

示例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;
                    }
                }
            }

        }
    }
}
 
开发者ID:snoozinsquatch,项目名称:unity-obb-downloader,代码行数:53,代码来源:DownloaderService.java


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