Clear user own apps data programmatically

后端 未结 2 1245
孤独总比滥情好
孤独总比滥情好 2021-01-11 09:36

I am developing an app where I want to allow the user to be able to set up that if they fail the login after a couple of attempts into the app, it will automatically delete

2条回答
  •  旧巷少年郎
    2021-01-11 10:10

    try this code .

    public void clearApplicationData() {
        File cache = getCacheDir();
        File appDir = new File(cache.getParent());
        if (appDir.exists()) {
            String[] children = appDir.list();
            for (String s : children) {
                if (!s.equals("lib")) {
                    deleteDir(new File(appDir, s));
                    Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
                }
            }
        }
    }
    
    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();
    }
    

提交回复
热议问题