• [置顶] 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();
    		}
    


  • 相关阅读:
    深入浅出JavaScript (一)初识
    “0”基础让你学会 GridView (一)
    VS 中PageLayout 属性设置
    ASP.NET Forms身份认证
    教务系统数据库设计 (一)
    深入浅出Javascript(三)创建自定义对象以及属性、方法
    .NET 中的Cache
    深入浅出JavaScript (二) 代码放置位置与执行顺序
    触发器特殊的存储过程
    ASP.NET与JavaScript轻松实现输入信息验证
  • 原文地址:https://www.cnblogs.com/anjon520/p/3249946.html
Copyright © 2020-2023  润新知