當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。