• android获取系统应用大小的方法


    <span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:18px;"></span></span><pre name="code" class="java">List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
    public PkgSizeObserver pkgsizeobserver = new PkgSizeObserver();
    try {
    	Method method;
    	method = this.getPackageManager().getClass().getMethod(	"getPackageSizeInfo",
    									new Class[] { String.class,
    											IPackageStatsObserver.class });
    	method.invoke(this.getPackageManager(),	packageInfo.packageName, pkgsizeobserver);
    				} catch (NoSuchMethodException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				} catch (IllegalAccessException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				} catch (IllegalArgumentException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				} catch (InvocationTargetException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				synchronized (pkgsizeobserver) {
    					try {
    						pkgsizeobserver.wait();
    					} catch (InterruptedException e) {
    						e.printStackTrace();
    					}
    				}
    				totalApp = pkgsizeobserver.cachesize + pkgsizeobserver.codesize
    						+ pkgsizeobserver.datasize;}


    
    
    <span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:18px;">
    </span></span>
    <span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:18px;">
    </span></span>
    <span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:18px;">PkgSizeObserver.class</span></span>
    <span style="font-size:18px;">//aidl文件形成的Bindler机制服务类
    public class PkgSizeObserver extends IPackageStatsObserver.Stub {
    	public long cachesize = 0;
    	public long datasize = 0;
    	public long codesize = 0;
    
    	/***
    	 * 回调函数。
    	 * 
    	 * @param pStatus
    	 *            ,返回数据封装在PackageStats对象中
    	 * @param succeeded
    	 *            代表回调成功
    	 */
    	@Override
    	public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)
    			throws RemoteException {
    		// TODO Auto-generated method stub
    
    		if(succeeded)
    		{
    			cachesize = pStats.cacheSize; // 缓存大小
    			datasize = pStats.dataSize; // 数据大小
    			codesize = pStats.codeSize; // 应用程序大小
    			synchronized (this) {
    				this.notifyAll();
    			}
    		}
    	}
    }</span>


  • 相关阅读:
    Qt支持中文显示
    C/C++ 知识点---LIB和DLL的区别与使用(网摘)
    Inno Setup
    C/C++ 知识点---字符串函数
    es5 JSON对象
    Es567严格模式
    mysql常用命令
    promise 获取文件内容
    postman连接不了localhost问题解决
    node---处理post请求
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/7286797.html
Copyright © 2020-2023  润新知