Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何清除其他应用程序的缓存_Java_Android_Caching - Fatal编程技术网

Java 如何清除其他应用程序的缓存

Java 如何清除其他应用程序的缓存,java,android,caching,Java,Android,Caching,我正在尝试清除手机上安装的所有应用程序的缓存 这是我的密码: public void clearApplicationData() { File cache = getCacheDir(); File parent1 = new File(cache.getParent()); File parent2 = new File(parent1.getParent()); if(parent2.exists()) { String[] children

我正在尝试清除手机上安装的所有应用程序的缓存

这是我的密码:

public void clearApplicationData() {
    File cache = getCacheDir();
    File parent1 = new File(cache.getParent());
    File parent2 = new File(parent1.getParent());
    if(parent2.exists()) {
        String[] children = parent2.list();
        for(String s : children){
            if(!s.equals("lib")){
                deleteDir(new File(parent2, s));
                Log.d("TAG", "File /data/data/APP_PACKAGE/" + s +" DELETED");
            }
        }
    }
}

public static boolean deleteDir(File dir) {
    Log.d("TAG", "Deleting :" + dir.getPath());
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            Log.d("TAG", "Delete :" + success +" \n");
            if (!success) {
                return false;
            }
        }
    }

    return dir.delete();
}
public void clearApplicationData(){
文件缓存=getCacheDir();
File parent1=新文件(cache.getParent());
File parent2=新文件(parent1.getParent());
if(parent2.exists()){
String[]children=parent2.list();
for(字符串s:子项){
如果(!s.equals(“lib”)){
deleteDir(新文件(parent2,s));
Log.d(“标签”,“文件/数据/数据/应用程序包/”+s+“删除”);
}
}
}
}
公共静态布尔deleteDir(文件目录){
Log.d(“标记”,“删除:”+dir.getPath());
if(dir!=null&&dir.isDirectory()){
String[]children=dir.list();
for(int i=0;i
在清单文件中,我声明了此权限:

<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />

但我总是将
parent2
设置为
null

我只能使用
parent1
删除我的应用程序缓存数据

请提供任何建议。