zoukankan      html  css  js  c++  java
  • [置顶] Android代码android获取3G或wifi流量信息

    android获取3G或wifi流量信息

    IBatteryStats battryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"));
        	byte[] data = null;
    		try {
    			data = battryStats.getStatistics();
    			Parcel parcel = Parcel.obtain();
    			parcel.unmarshall(data, 0, data.length);
    			parcel.setDataPosition(0);
    			final BatteryStatsImpl impl = BatteryStatsImpl.CREATOR.createFromParcel(parcel);
    			try {
    				Thread.sleep(1000);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    			long length1_1 = impl.getTotalTcpBytesReceived(BatteryStats.STATS_CURRENT);
    			long length1_2 = impl.getTotalTcpBytesReceived(BatteryStats.STATS_LAST);
    			long length1_3 = impl.getTotalTcpBytesReceived(BatteryStats.STATS_TOTAL);
    			long length1_4 = impl.getTotalTcpBytesReceived(BatteryStats.STATS_UNPLUGGED);
    			
    			long length2_1 = impl.getTotalTcpBytesSent(BatteryStats.STATS_CURRENT);
    			long length2_2 = impl.getTotalTcpBytesSent(BatteryStats.STATS_LAST);
    			long length2_3 = impl.getTotalTcpBytesSent(BatteryStats.STATS_TOTAL);
    			long length2_4 = impl.getTotalTcpBytesSent(BatteryStats.STATS_UNPLUGGED);
    			
    			long length3_1 = impl.getMobileTcpBytesReceived(BatteryStats.STATS_CURRENT);
    			long length3_2 = impl.getMobileTcpBytesReceived(BatteryStats.STATS_LAST);
    			long length3_3 = impl.getMobileTcpBytesReceived(BatteryStats.STATS_TOTAL);
    			long length3_4 = impl.getMobileTcpBytesReceived(BatteryStats.STATS_UNPLUGGED);
    			
    			long length4_1 = impl.getMobileTcpBytesSent(BatteryStats.STATS_CURRENT);
    			long length4_2 = impl.getMobileTcpBytesSent(BatteryStats.STATS_LAST);
    			long length4_3 = impl.getMobileTcpBytesSent(BatteryStats.STATS_TOTAL);
    			long length4_4 = impl.getMobileTcpBytesSent(BatteryStats.STATS_UNPLUGGED);
    			
    			Log.d("TAG", "total tcp R dataC:" + length1_1/(1024*1024));
    			Log.d("TAG", "total tcp R dataL:" + length1_2/(1024*1024));
    			Log.d("TAG", "total tcp R dataT:" + length1_3/(1024*1024));
    			Log.d("TAG", "total tcp R dataU:" + length1_4/(1024*1024));
    			
    			Log.d("TAG", "total tcp S dataC:" + length2_1/(1024*1024));
    			Log.d("TAG", "total tcp S dataL:" + length2_2/(1024*1024));
    			Log.d("TAG", "total tcp S dataT:" + length2_3/(1024*1024));
    			Log.d("TAG", "total tcp S dataU:" + length2_4/(1024*1024));
    			
    			Log.d("TAG", "M R tcp dataC:" + length3_1/(1024*1024));
    			Log.d("TAG", "M R tcp dataL:" + length3_2/(1024*1024));
    			Log.d("TAG", "M R tcp dataT:" + length3_3/(1024*1024));
    			Log.d("TAG", "M R tcp dataU:" + length3_4/(1024*1024));
    			
    			Log.d("TAG", "M S tcp dataC:" + length4_1/(1024*1024));
    			Log.d("TAG", "M S tcp dataL:" + length4_2/(1024*1024));
    			Log.d("TAG", "M S tcp dataT:" + length4_3/(1024*1024));
    			Log.d("TAG", "M S tcp dataU:" + length4_4/(1024*1024));
    			
    		} catch (RemoteException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    


  • 相关阅读:
    WCF 第四章 绑定 在多个绑定上暴露一个服务契约
    WCF 第五章 行为 事务跨操作事务流
    WCF 第五章 导出并发布元数据(服务行为)
    WCF 第五章 行为 通过配置文件暴露一个服务行为
    WCF 第五章 不支持会话的绑定的默认并发和实例
    WCF 第五章 并发和实例(服务行为)
    WCF 第五章 行为 总结
    WCF 第四章 绑定 绑定元素
    WCF 第五章 行为 事务之选择一个事务协议OleTx 或者WSAT
    WCF 第四章 绑定 比较各种绑定的性能和可扩展性
  • 原文地址:https://www.cnblogs.com/anjon520/p/3249946.html
Copyright © 2011-2022 走看看