Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • how to identify the network type in android?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 423
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: