通過查看手機設定(setting)原始碼,發現它裡面擷取應用大小和緩衝大小是通過PackageManager裡面的getPackageSizeInfo方法。然而此方法時私人的,因此通過反射調用此方法。裡面要用到IPackageStatsObserver介面,它是一個aidl方式進行訪問。
DemoActivity Map<String, CacheInfo> == HashMap<String, CacheInfo>=<PackageInfo> packageinfos ==== = onItemClick(AdapterView<?> position, "haha"= "android.intent.action.VIEW""android.intent.category.DEFAULT""android.intent.category.VOICE_LAUNCH"="pkg", info.getPackname()); getAppSize(= PackageManager..getMethod("getPackageSizeInfo", Class[]{String. onGetStatsCompleted(PackageStats pStats, succeeded) cachesize = codesize = datasize == MyAdapter Set<Entry<String, CacheInfo>> List<CacheInfo>== ArrayList<CacheInfo> (Entry<String, CacheInfo> Object getItem( getItemId( View getView(= = (convertView == = View.inflate(DemoActivity., R.layout.item, =====
String getDataSize( (size < 0= 0= DecimalFormat("####.00" (size < 1024 size + "bytes" (size < 1024 * 1024 kbsize = size / formater.format(kbsize) + "KB" (size < 1024 * 1024 * 1024 mbsize = size / 1024f / formater.format(mbsize) + "MB" (size < 1024 * 1024 * 1024 * 1024 gbsize = size / 1024f / 1024f / formater.format(gbsize) + "GB" "size: error" String getKBDataSize( (size < 0= 0 getDataSize(size * 1024
aidl檔案:IPackageStatsObserver.aidl
onGetStatsCompleted(in PackageStats pStats,
PackageStats.aidl