Android代码----android获取3G或wifi流量信息 android获取3G或wifi流量信息:
[java] view plaincopyprint? 1. IBatteryStats battryStats =
IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"));
2. byte[] data = null;
3. try {
4. data = battryStats.getStatistics();
5. Parcel parcel = Parcel.obtain();
6. parcel.unmarshall(data, 0, data.length);
7. parcel.setDataPosition(0);
8. final BatteryStatsImpl impl =
BatteryStatsImpl.CREATOR.createFromParcel(parcel);
9. try {
10. Thread.sleep(1000);
11. } catch (InterruptedException e) {
12. e.printStackTrace();
13. }
14. long length1_1 = impl.getTotalTcpBytesReceived(BatteryStats.STATS_CURRENT);
15. long length1_2 = impl.getTotalTcpBytesReceived(BatteryStats.STATS_LAST);
16. long length1_3 = impl.getTotalTcpBytesReceived(BatteryStats.STATS_TOTAL);
17. long length1_4 =
impl.getTotalTcpBytesReceived(BatteryStats.STATS_UNPLUGGED);
18.
19. long length2_1 = impl.getTotalTcpBytesSent(BatteryStats.STATS_CURRENT);
20. long length2_2 = impl.getTotalTcpBytesSent(BatteryStats.STATS_LAST);
21. long length2_3 = impl.getTotalTcpBytesSent(BatteryStats.STATS_TOTAL);
22. long length2_4 = impl.getTotalTcpBytesSent(BatteryStats.STATS_UNPLUGGED); 23.
24. long length3_1 =
impl.getMobileTcpBytesReceived(BatteryStats.STATS_CURRENT);
25. long length3_2 = impl.getMobileTcpBytesReceived(BatteryStats.STATS_LAST);
26. long length3_3 = impl.getMobileTcpBytesReceived(BatteryStats.STATS_TOTAL);