There are various network type available in android, for example- 2G,3G GPRS etc.
If you need to find-out the current network type of your android device, than you just need to implement the method given below  in your utility class :-
    public static String getNetworkType(Context context)
{
    String netwrokType="Not available";
    TelephonyManager tm =(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);      
    if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA)) {
        netwrokType= "3g";
    } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPAP)) {
        netwrokType= "4g"; 
    } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) {
        netwrokType= "GPRS";
    } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE)) {
        netwrokType= "EDGE 2g";
    } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPA)) {
        netwrokType= "HSPA";
    }
    return netwrokType;
}
You can just call this method when ever you want to identify the network type.
Also make sure to add this permission to your AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>;
Hope you find it helpful :)
                       
                    
0 Comment(s)