0

I am trying to download some file in android app. For this I have to compare android default settings download via WiFi or WiFi/mobile-data status. Is it possible to get this default connection status in android application.

Expected: Settings->securitysettings->security policy update->Download updates via->Wi-Fi only and WiFi or mobile networks. Here is it possible to get this network selection status in android application.

user
  • 1,659
  • 1
  • 18
  • 25
  • Does this answer your question? [Check whether mobile is using WIFI or Data/3G](https://stackoverflow.com/questions/17148371/check-whether-mobile-is-using-wifi-or-data-3g) – Niki Dec 06 '19 at 05:23
  • Hi, this all the connection status like WIFI or Data.. but i need to know default app update or download via Wifi/Data ..in Setting Download and App Updates via wifi, wifi/Mobile data – user Dec 06 '19 at 05:25
  • Could you please elaborate your question in a more defined way? – Anu Bhalla Dec 06 '19 at 05:29

1 Answers1

0

You Can check which connection App is using as of now using this appraoch

static String getNetworkType(Context applicationContext) {
        ConnectivityManager cm = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = null;
        if (cm != null) {
            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
                case TelephonyManager.NETWORK_TYPE_GSM:      // api<25: replace by 16
                    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 12
                case TelephonyManager.NETWORK_TYPE_EHRPD:    // api<11: replace by 14
                case TelephonyManager.NETWORK_TYPE_HSPAP:    // api<13: replace by 15
                case TelephonyManager.NETWORK_TYPE_TD_SCDMA: // api<25: replace by 17
                    return "3G";
                case TelephonyManager.NETWORK_TYPE_LTE:      // api<11: replace by 13
                case TelephonyManager.NETWORK_TYPE_IWLAN:    // api<25: replace by 18
                case 19: // LTE_CA
                    return "4G";
                default:
                    return "Unknown";
            }
        }
        return "Unknown";
    }
Manoj Mohanty
  • 372
  • 2
  • 10