繁体   English   中英

Android:当有人从Google Play商店下载应用程序更新时,是否可以自动强制清除应用程序数据/缓存?

[英]Android: Is there a way to automatically, forcefully clear app data/cache when one downloads an update for the app from Google Play store?

当有人从Google Play商店下载应用程序更新时,是否可以自动强制清除应用程序数据/缓存?

您是手动吗? 您可以在设置中转到应用程序管理器,并且应该有一个选项来删除保存的数据和缓存的数据。

只需将当前的versionCode保存在sharedPref中,然后检查当前版本是否比手动删除所有数据新。

用于删除共享的首选使用:

PreferenceManager.getDefaultSharedPreferences(context).edit().clear().apply();

或者此方法对于删除外部getExternalStorageDirectory()目录也很有用:

            final String dirPath = context.getFilesDir().getParent() + "/shared_prefs";
            final File sharedPrefFolder = new File(dirPath);
            if (sharedPrefFolder.exists() && sharedPrefFolder.isDirectory()) {
                String[] children = sharedPrefFolder.list();
                for (String aChildren : children) {
                    new File(sharedPrefFolder, aChildren).delete();
                }
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM