最近有一个需求,需要在最近任务页面的一键清除任务按钮中添加一键清除页面缓存的功能,网上找了一圈,看不到什么便捷的版本,基本上是遍历xxx/cache然后删除,其实是没有这个必要的。
模仿:想一想,哪里有相似功能?原生系统设置的应用信息里。
代码位置:packages\apps\Settings\src\com\android\settings\applications
类名:com.android.settings.applications. AppStorageSettings
看到这个代码时,才发现,原来如此简单。。
那么这就比较好搞定了。简陋写法:import android.content.pm.IPackageDataObserver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import java.util.List;
import android.os.SystemProperties;
privateClearCacheObserver mClearCacheObserver;
voidclearAllAplicationCache(){
newThread(newRunnable() {
@Override
<