我怎样才能清除Android应用程序缓存? [英] How can I clear the Android app cache?
问题描述
我写它可以将所有的第三方应用程序编程明确的应用程序缓存安装在设备上的应用程序。以下是code段为Android 2.2
公共静态无效trimCache(上下文myAppctx){
上下文的背景下= myAppctx.createPackageContext(com.thirdparty.game
Context.CONTEXT_INCLUDE_CO | Context.CONTEXT_IGNORE_SECURITY);
文件cachDir = context.getCacheDir();
Log.v(裁剪,目录+ cachDir.getPath());
如果(cachDir =空&安培;!&安培; cachDir.isDirectory()){
Log.v(修剪,能读+ cachDir.canRead());
的String []文件名= cachDir.list();
//迭代作为文件名并删除
}
}
我的表现有以下权限:
android.permission.CLEAR_APP_CACHE
android.permission.DELETE_CACHE_FILES
现在的问题是,高速缓存目录的名称印,但文件的列表 cachDir.list()
总是返回null。我不能够删除缓存目录,因为文件列表总是空。
有没有清除应用程序缓存的任何其他方式?
android.permission.CLEAR_APP_CACHEandroid.permission.DELETE_CACHE_FILES
普通的SDK应用程序不能持有 DELETE_CACHE_FILES
许可。虽然你可以按住 CLEAR_APP_CACHE
,没有什么在Android SDK,使您可以清除应用程序的缓存。
有没有清除应用程序缓存的任何其他方式?
欢迎您来清除自己的缓存,删除在缓存中的文件。
I am writing a app which can programatically clear application cache of all the third party apps installed on the device. Following is the code snippet for Android 2.2
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
}
}
My manifest has following permissions:
android.permission.CLEAR_APP_CACHE
android.permission.DELETE_CACHE_FILES
Now the problem is that the name of the cache directory is printed but the list of files cachDir.list()
always returns null. I am not able to delete the cache directory since the file list is always null.
Is there any other way to clear the application cache?
"android.permission.CLEAR_APP_CACHE" android.permission.DELETE_CACHE_FILES"
Ordinary SDK applications cannot hold the DELETE_CACHE_FILES
permission. While you can hold CLEAR_APP_CACHE
, there is nothing in the Android SDK that allows you to clear an app's cache.
Is there any other way to clear the application cache?
You are welcome to clear your own cache by deleting the files in that cache.
这篇关于我怎样才能清除Android应用程序缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!