How to check mobile data usage programmatically?

不羁的心 提交于 2019-12-10 19:29:39

问题


The question is pretty straight forward, How do I find out how much mobile data (in GB or MB) has the user used in the current month?

As it has been reported as off topic, I want to clarify that the data usage is supposed to be checked via code in an app.

Is there some code I can use to check for the users used data?


回答1:


See: https://developer.android.com/reference/android/net/TrafficStats.html

Try:

Toast.makeText(this, android.net.TrafficStats.getMobileRxBytes()+"Bytes", Toast.LENGTH_SHORT).show();

getMobileRxBytes() Return number of bytes received across mobile networks since device boot.



来源:https://stackoverflow.com/questions/46025444/how-to-check-mobile-data-usage-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!