0

i've making a file transfer app. i am using download manager in this. if backgroud data restriction is enabled, the transfers are being queued by the download manager.

i want to warn the user that file transfer doenst work if it is enabled.

is there a way to know if background data restriction is enabled programatically? I want this to happen even in Android Marshmallow.

Thanks in advance.

1 Answers1

0

The below code works for my phone of Android 10 .

 @RequiresApi(api = Build.VERSION_CODES.N)
    public boolean checkBackgroundDataRestricted() {
        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        Log.i("test","getRestrictBackgroundStatus ="+connMgr.getRestrictBackgroundStatus());
        switch (connMgr.getRestrictBackgroundStatus()) {
            case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED:
                // Background data usage and push notifications are blocked for this app
                return true;

            case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED:
            case ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED:
                // Data Saver is disabled or the app is whitelisted
                return false;
        }
        return false;
    }

enter image description here

enter image description here

simon5678
  • 249
  • 1
  • 5