1.流量统计的原理
(1)操作系统分配每个应用程序一个固定的编号(id)
(2)代码
<span style="font-size:14px;">public class TrafficManagerActivity extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//1.获取一个包管理器
PackageManager pm=context.getPackageManager();
//2.遍历手机操作系统获得所有的应用程序的uid
List<ApplicationInfo> appliactaionInfos=pm.getInstalledApplications(0);
for(ApplicationInfo applicationInfo:applicationInfos){
int uid=applicationInfo.uid;
long tx=TrafficStats.getUidTxBytes(uid);//发送的上传流量byte
long rx=TrafficStats.getUidRxBytes(uid);//发送的上传流量byte
}
}</span>
2.sliding抽屉的简单实现
(1)
TrafficStats.getMobileTxBytes();//获取3G/2G网络上传总流量
TrafficStats.getMobileRxBytes();//手机2G/3G下载的总流量
TrafficStats.getTotalTxBytes();//手机全部网络接口,包括WiFi,3g,2g上传的总流量
TrafficStats.getTotalRxBytes();//手机全部网络接口,包括WiFi,3g,2g下载的总流量
(2)只能从下往上,从右往左滑动
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- 抽屉的位置:orientation -->
<SlidingDrawer
android:id="@+id/mydraw"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:content="@+id/b"
android:handle="@+id/a"
android:orientation="vertical" >
<!-- 把手的布局,也可以为一个布局 -->
<ImageView
android:id="@id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<!-- 内容的布局 -->
<LinearLayout
android:id="@id/b"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#22000000"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是内容" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
3.手机杀毒的原理
(1)布局雷达扫描动画-----两个图片重叠,让上面的图片旋转
6.横竖屏切换的生命周期
(1)横竖屏切换会销毁原来的Activity
(2)忽略横竖屏切换
a.在Activity配置文件中配置
<activity
android:configChanges="orientation|keyboardHidden|screenSize"
></activity>
7.利用反射获取缓存和应用程序大小信息
public class CleanCacheActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
initUI();
}
private void initUI() {
setContentView(R.layout.activity_clean_cache);
PackageManager packageManager = getPackageManager();
/**
* 接收2个参数
* 第一个参数接收一个包名
* 第二个参数接收aidl的对象
*/
// * @hide
// */
// public abstract void getPackageSizeInfo(String packageName,
// IPackageStatsObserver observer);
// packageManager.getPackageSizeInfo();
//安装到手机上面所有的应用程序
List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);
for (PackageInfo packageInfo : installedPackages) {
getCacheSize(packageInfo);
}
}
private void getCacheSize(PackageInfo packageInfo) {
try {
Class<?> clazz = getClassLoader().loadClass("packageManager");
//通过反射获取到当前的方法
Method method = clazz.getDeclaredMethod("getPackageSizeInfo", String.class,IPackageStatsObserver.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}