標籤:lap gets str zed boolean font bin content tcl
<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 blocke.printStackTrace();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalArgumentException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (InvocationTargetException e) {// TODO Auto-generated catch blocke.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 * 代表回調成功 */@Overridepublic void onGetStatsCompleted(PackageStats pStats, boolean succeeded)throws RemoteException {// TODO Auto-generated method stubif(succeeded){cachesize = pStats.cacheSize; // 緩衝大小datasize = pStats.dataSize; // 資料大小codesize = pStats.codeSize; // 應用程式大小synchronized (this) {this.notifyAll();}}}}</span>
android擷取系統應用大小的方法