0

On the android 11 device, I want to check for the "data limit" option is enabled or disabled on the device those are running Android 11. Currently, I am using NetowrkPolicy, NetworkPolicyManager, NetworkTemplate classes. But those all are hidden APIs and now blocked or restricted in targeting device android 11. And code is below -

        if (networkPolicy.limitBytes == NetworkPolicy.LIMIT_DISABLED) {
           //currentlly data limit is not enabled on device
        } else {
            //currentlly data limit is enabled on device, so that we can calculate how much is remaining.
        }

I have already searched in for ConnectivityManager [Not provide much information related to my task]. I am guessing this may be currently in any setting package or not sure.

Note - I just want to check if the option is enabled or not on device those are targeting android 11.

Update - 1

I am not sure how this can be useful - KEY_DATA_LIMIT_THRESHOLD_BYTES_LONG (Controls the cellular data limit), this says - If the user uses more than this amount of data in their billing cycle, as defined by KEY_MONTHLY_DATA_CYCLE_DAY_INT, cellular data will be turned off by the user's phone. If the value is set to DATA_CYCLE_THRESHOLD_DISABLED, the data limit will be disabled.

Bajrang Hudda
  • 3,028
  • 1
  • 36
  • 63
  • For this and other questions on non-SDK hidden APIs, the key is to ask yourself what the underlying purpose of using the non-SDK hidden API is. In your case, you want to get the user's "data limit". Is it to avoid downloads on a slow connection? Is it to avoid downloads if the connection is "metered"? Then there may be a "public" alternative to that use case: see https://developer.android.com/about/versions/11/features/5g#meteredness : Does `NetworkCapabilities.NET_CAPABILITY_NOT_METERED` (or `NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED`) help? – Peter O. Apr 20 '21 at 07:42
  • @PeterO. Thank you for pitching in, Actually, I want to show a warning based on it, if it's enabled then will show the remaining data based on the set limit. – Bajrang Hudda Apr 20 '21 at 08:38
  • @PeterO. I have updated my question, I am not much sure about KEY_DATA_LIMIT_THRESHOLD_BYTES_LONG from android.telephony.CarrierConfigManager class. – Bajrang Hudda Apr 20 '21 at 09:26

0 Answers0