Get Network type

后端 未结 13 1023
后悔当初
后悔当初 2020-12-01 08:35

I\'ve been trying to retrive the current network type, but no success

when i say network type: i refer to know this info: if the type is: NETWORK_TYPE_IDEN

相关标签:
13条回答
  • 2020-12-01 09:32

    Better use would be:

        NetworkInfo activeNetworkInfo = ((ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        if (activeNetworkInfo == null) return false;
        switch (activeNetworkInfo.getType()) {
            case ConnectivityManager.TYPE_WIFI:
                return true;
        }
    //        public static final int TYPE_BLUETOOTH = 7;
    //        public static final int TYPE_DUMMY = 8;
    //        public static final int TYPE_ETHERNET = 9;
    //        public static final int TYPE_MOBILE = 0;
    //        public static final int TYPE_MOBILE_DUN = 4;
    //        /** @deprecated */
    //        @Deprecated
    //        public static final int TYPE_MOBILE_HIPRI = 5;
    //        /** @deprecated */
    //        @Deprecated
    //        public static final int TYPE_MOBILE_MMS = 2;
    //        /** @deprecated */
    //        @Deprecated
    //        public static final int TYPE_MOBILE_SUPL = 3;
    //        public static final int TYPE_VPN = 17;
    //        public static final int TYPE_WIFI = 1;
    //        public static final int TYPE_WIMAX = 6;
    

    Which other types you want to define and handle is up to you...

    For those wanting a string identifier, better use:

    activeNetworkInfo.getTypeName()
    activeNetworkInfo.getSubtypeName()
    
    0 讨论(0)
提交回复
热议问题