3

如何在android手机中检查网络是否连接..(网络意味着没有互联网连接,其简单的移动网络如IDEA,AIRTEL等......)请帮帮我

4

4 回答 4

0

好的,所以您只想检查网络连接?这个方法似乎很适合它! http://smartandroidians.blogspot.co.uk/2010/03/checking-network-connection-in-android.html 试一试,希望它会排序:)

于 2012-08-16T10:00:48.317 回答
0

您可以使用以下方式检索 SIM 卡和网络运营商TelephonyManager

TelephonyManager telephonyManager =((TelephonyManager) 
Context.getSystemService(Context.TELEPHONY_SERVICE));

// Network operator IDEA,AIRTEL...
String networkOperatorName = telephonyManager.getNetworkOperatorName();

// sim operator IDEA,AIRTEL,BSNL,MTNL...
String simOperatorName = telephonyManager.getSimOperatorName();
于 2012-08-16T10:05:14.060 回答
0

检查TelephonyManager类。这可能会在很多方面帮助您。

于 2012-08-16T10:05:19.473 回答
0
/**
 * Checking whether net connection is available or not.
 * 
 * @param nContext
 * @return true if net connection is avaible otherwise false
 */
public static boolean isNetworkAvailable(Context nContext) {
    boolean isNetAvailable = false;
    if (nContext != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) nContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (mConnectivityManager != null) {
            boolean mobileNetwork = false;
            boolean wifiNetwork = false;
            boolean mobileNetworkConnecetd = false;
            boolean wifiNetworkConnecetd = false;
            NetworkInfo mobileInfo = mConnectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            NetworkInfo wifiInfo = mConnectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            if (mobileInfo != null)
                mobileNetwork = mobileInfo.isAvailable();
            if (wifiInfo != null)
                wifiNetwork = wifiInfo.isAvailable();
            if (wifiNetwork == true || mobileNetwork == true) {
                if (mobileInfo != null)
                    mobileNetworkConnecetd = mobileInfo
                            .isConnectedOrConnecting();
                wifiNetworkConnecetd = wifiInfo.isConnectedOrConnecting();
            }
            isNetAvailable = (mobileNetworkConnecetd || wifiNetworkConnecetd);
        }
    }
    return isNetAvailable;

}

还要在清单权限中添加以下标签:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
于 2015-04-08T09:45:52.857 回答