【发布时间】:2012-12-13 07:02:20
【问题描述】:
我正在编写一个应用程序,它可以以编程方式清除设备上安装的所有第三方应用程序的应用程序缓存。以下是 Android 2.2 的代码 sn-p
public static void trimCache(Context myAppctx) {
Context context = myAppctx.createPackageContext("com.thirdparty.game",
Context.CONTEXT_INCLUDE_CO|Context.CONTEXT_IGNORE_SECURITY);
File cachDir = context.getCacheDir();
Log.v("Trim", "dir " + cachDir.getPath());
if (cachDir!= null && cachDir.isDirectory()) {
Log.v("Trim", "can read " + cachDir.canRead());
String[] fileNames = cachDir.list();
//Iterate for the fileName and delete
}
}
我的清单具有以下权限:
android.permission.CLEAR_APP_CACHE
android.permission.DELETE_CACHE_FILES
现在的问题是打印了缓存目录的名称,但文件列表cachDir.list() 总是返回空值。我无法删除缓存目录,因为文件列表始终为空。
还有其他方法可以清除应用程序缓存吗?
【问题讨论】:
-
你不需要root设备吗?
标签: android