Get Network type

后端 未结 13 1086
后悔当初
后悔当初 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:28

    I am using this function:

    public String get_network()
           {Activity act=(Activity)context;
            String network_type="UNKNOWN";//maybe usb reverse tethering
            NetworkInfo active_network=((ConnectivityManager)act.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
            if (active_network!=null && active_network.isConnectedOrConnecting())
               {if (active_network.getType()==ConnectivityManager.TYPE_WIFI)
                   {network_type="WIFI";
                   }
                else if (active_network.getType()==ConnectivityManager.TYPE_MOBILE)
                     {network_type=((ConnectivityManager)act.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo().getSubtypeName();
                     }
               }
            return network_type;
           }
    

提交回复
热议问题