Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.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 - Fatal编程技术网

Java 从我的应用程序中清除另一个应用程序的数据

Java 从我的应用程序中清除另一个应用程序的数据,java,android,Java,Android,我想删除另一个应用程序数据,比如说我想从我的应用程序中删除facebook的应用程序数据或whatsapp数据。 我试过了,但没有成功;s表示,它无法清除其他应用程序的数据,因为每个android应用程序都运行在一个沙箱中,这会屏蔽其数据,使其无法从其范围外访问 那么,我是否可以将用户重定向到设置屏幕并以编程方式显式单击清除数据 我的片段: public void clearApplicationData(String packageName) { File cache = getCa

我想删除另一个应用程序数据,比如说我想从我的应用程序中删除facebook的应用程序数据或whatsapp数据。 我试过了,但没有成功;s表示,它无法清除其他应用程序的数据,因为每个android应用程序都运行在一个沙箱中,这会屏蔽其数据,使其无法从其范围外访问


那么,我是否可以将用户重定向到设置屏幕并以编程方式显式单击清除数据

我的片段:

 public void clearApplicationData(String packageName) {
    File cache = getCacheDir();
    File appDir1 = new File(cache.getParent()).getParentFile();
    File appDir = new File(appDir1.getAbsolutePath() + "/" + packageName);
    if (appDir.exists()) {
        String[] children = appDir.list();
        for (String s : children) {
            if (!s.equals("lib")) {
                deleteDir(new File(appDir, s));
            }
        }
    }
}

public static boolean deleteDir(File dir) {
    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]));
            if (!success) {
                return false;
            }
        }
    }
    return dir.delete();
}



  List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    clearApplicationData(packageInfo.packageName);
public void clearApplicationData(字符串packageName){
文件缓存=getCacheDir();
File appDir1=新文件(cache.getParent()).getParentFile();
File appDir=新文件(appDir1.getAbsolutePath()+“/”+packageName);
if(appDir.exists()){
String[]children=appDir.list();
for(字符串s:子项){
如果(!s.equals(“lib”)){
deleteDir(新文件(appDir,s));
}
}
}
}
公共静态布尔deleteDir(文件目录){
if(dir!=null&&dir.isDirectory()){
String[]children=dir.list();
for(int i=0;i列表

“我是否可以将用户重定向到设置屏幕并以编程方式显式单击清除数据?”--否。那么,你的意思是说,不可能实现清除其他应用程序数据的机制?你需要一个特殊的系统权限,而你无法获得该权限。例如,尝试从应用程序运行shell
pm安装一些.apk
如果没有您无法获得的权限,它将失败。当您使用adb时,这将起作用。