如何获得编程数据使用限制用户对Android操作系统的配置设置?如何获得、操作系统、数据、用户

2023-09-13 01:01:25 作者:风绾梦境悠

用户可以在数据使用屏幕定义LIMITE和/或移动数据使用量的警告限制。所以,我怎么能得到这个信息由code?

User can define at Data Usage screen a limite and/or a warning limit for mobile data usage. So how can I get this information by code?

本机操作系统的数据使用配置屏幕。

Screen of Data Usage configuration of native OS.

我想限定值和报警值。

我已经试过,但没有工作,总是返回NULL双方:

I've already tried this but not work and always return NULL to both:

final Long recommendedBytes = DownloadManager.getRecommendedMaxBytesOverMobile( this.context );
final Long maximumBytes = DownloadManager.getMaxBytesOverMobile( this.context );

// recommendedBytes and maximumBytes are NULL

和 TrafficStats 类只是有一个数据传送而不是限制。

And TrafficStats class just have a data transferred not the limits.

推荐答案

在天寻找和研究这个问题我无法找到一个答案。娄我将解​​除每次我做的尝试。

After days searching and research about this problem I couldn't find a answer for that. Bellow I will lift every attempt that I did.

1。 下载管理器

1. Download Manager

通过这个类,你就可以开始下载了任何网络或设备   状态,它会处理所有状态如网损,设备重启,   等等...

With this class you can start download over any network or device state and it will handle all states e.g. network loss, device reboot, etc...

有两种方法称为getMaxBytesOverMobile和   getRecommendedMaxBytesOverMobile,他们是pretty的候选人   要解决这个问题,在第一次。但在code测试,   Download经理implementantion 研究,我会发现,有   没办法通过下载管理器来获得thoose值。

There are two methods called getMaxBytesOverMobile and getRecommendedMaxBytesOverMobile, they was a pretty candidate to solve this problem at first time. But after code tests and Download Manager implementantion research I'd found that there is no way to get thoose values by DownloadManager.

原因

Thoose方法调用Settings.Secure.getLong与他们   相应的标签   Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE和   Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE在   在又使得调用一个懒惰的String地图内内   内部类名为NameValueCache.

Thoose methods call Settings.Secure.getLong with they respective labels Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE and Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE in the turn makes a call to a lazy String map inside inside a inner class called NameValueCache.

好了,但迄今为止没有任何内部类或设置实施它的   自用 DOWNLOAD_MAX_BYTES_OVER_MOBILE 或    DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE 里。

Ok so far but none of inner classes or Settings implementation it self use DOWNLOAD_MAX_BYTES_OVER_MOBILE or DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE inside.

我认为是懒惰的地图由第三实体填充,是什么   实际发生,所以我找到了NameValueTable 设置   该处理新的值懒地图内部类。该   putString是保护方法的调用由 Settings.Secure   和 Settings.System 的Secure和   System).

I considered the lazy map was populate by a third entity, what actually happens, so I found the NameValueTable Settings inner class that handle the new values to lazy map. The putString is a protected method call by Settings.Secure and Settings.System inner classes (calls of Secure and System).

所以,我可以断定,如果OS implementantion不要把thoose字符串值,我不能让他们。

2。 TrafficStats

只是一个快速浏览一下官方的参考,我可以看到,它会   不帮我,因为这个类只是提供的字节数和   包是自去年设备启动贩卖。

Just a quick look on official reference I could notice that it will not help me because this class just provide the amount of bytes and packages that was trafficked since last device boot.

http://developer.android.com/reference/android/net/TrafficStats.html

3。 NetworkPolicyManager和NetworkPolicy

3. NetworkPolicyManager and NetworkPolicy

由于@bina张贴这里的两个类是隐藏的,不能   普通应用例如是使用这将刊登在谷歌播放。

盘点Android有iPhone无的10项功能

As @bina posted here the both classes are hidden and could not be use by normal apps e.g. that will be published in Google Play.

http://stackoverflow.com/a/24445424/575643

4。 ConnectivityManager

总之,你就可以得到NetworkInfo那没有提供   有关用户preferences多的信息(真是没话说!)。只需提供   关于网络和信息例如移动网络提供商。

In short, you just can get the NetworkInfo that not provide much information about user preferences (really none!). Just provide informations about network and e.g. mobile network provider.

http://developer.android.com/reference/android/net/ConnectivityManager.html

毕竟我认为没有办法今天得到这个信息。请如果你读它,并找到一种方法,张贴在这里!

After all I assume that no way to get this information nowadays. Please if you read it and found a way post here!

感谢所有。

PS:不好意思用英语的错误。的