reactjs - 在 react-native 项目中清除 android 和 iOS 中的应用程序数据?
问题描述
嗨,我知道以前有人问过类似的问题。提到的解决方案没有帮助。
试过这个`
File cache = getReactApplicationContext().getCacheDir(); File appDir = new File(cache.getParent()); if (appDir.exists()) { String[] test = cache.list(); Log.d("before", Arrays.toString(test)); for (String s : test) { //if (s.contains(".pdf") || s.contains(".mp4")) { deleteDir(new File(cache, s)); Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************"); // } } Log.d("After delete", Arrays.toString(cache.list())); } 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(); }
`但什么也没发生
试过这个`
try{ if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) { ((ActivityManager) getReactApplicationContext().getSystemService(ACTIVITY_SERVICE)).clearApplicationUserData(); // note: it has a return value! } else { String packageName = getCurrentActivity().getPackageName(); Runtime runtime = Runtime.getRuntime(); runtime.exec("pm clear " + packageName); } } catch(error){console.log("error"+error)}`
在控制台中收到警告 要求循环是允许的,但可能导致未初始化的值。考虑重构以消除对循环的需求。应用程序已退出,这是不鼓励的。我需要在清理数据后显示登录页面。
任何见解???
解决方案
推荐阅读
- javascript - 使用 JavaScript 倒数
- python - 如何使用 Selenium 在 div 的索引中查找多个元素
- c - 用函数和指针改变数组的元素
- javascript - 由于模板中的 css,单选按钮被禁用
- python - 使用进度指示器在 python 中创建大文件
- python - Python,将用户输入存储在一个数组中,然后将它们打印在一首诗中
- jquery - 我如何从以下列表视图中选择按钮单击时的 val() ,
- ubuntu - pandoc无法在ubuntu中将表从markdown转换为epub
- python-3.x - Python 请求使用证书值而不是路径
- javascript - 如何将数据从 C# 传递到 javascript 函数?