2

I'm trying to find the current frequency band.

I read a lot on this issue in the past few days but I didn't found anything. I need solution for it (code not an app).

If I can access to this data by getting root access it is also OK.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130

1 Answers1

1

For network type You can use this method (from here):

public static String getNetworkClass(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);      
    NetworkInfo info = cm.getActiveNetworkInfo();
    if(info==null || !info.isConnected())
        return "-"; //not connected
    if(info.getType() == ConnectivityManager.TYPE_WIFI)
        return "WIFI";
    if(info.getType() == ConnectivityManager.TYPE_MOBILE){
        int networkType = info.getSubtype();
        switch (networkType) {
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_1xRTT:
            case TelephonyManager.NETWORK_TYPE_IDEN: //api<8 : replace by 11
                return "2G";
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_EVDO_B: //api<9 : replace by 14
            case TelephonyManager.NETWORK_TYPE_EHRPD:  //api<11 : replace by 12
            case TelephonyManager.NETWORK_TYPE_HSPAP:  //api<13 : replace by 15
                return "3G";
            case TelephonyManager.NETWORK_TYPE_LTE:    //api<11 : replace by 13
                return "4G";
            default:
                return "?";
         }
    }
    return "?";
}

But to get frequency You should work directly with GSM module of phone via AT Commands like AT!BAND? for Sierra modules or AT+CBAND? for other. It's also possible, but with hard way like this. Or may be something like that but it hardly ever.

Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79