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
or NETWORK_TYPE_UMTS
.. and so on..
i tried to use:
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
or
NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo
(ConnectivityManager.TYPE_MOBILE);
but no success..
i am doing this coz i wanna know if the current network is IDEN, or if the current network is connected through wifi..
In Android API LEVEL 30 getNetworkType has deprecated. Use getDataNetworkType() , and provide android.permission.READ_PHONE_STATE
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With