- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想在 Android Marshmallow 6.0 中以编程方式清除我的应用程序缓存。我尝试了以下代码,但它在 Marshmallow 中不起作用。我在堆栈溢出中读到以下代码已从 API 级别 19 开始弃用。我在我的 Manifests.xml 中添加了 CLEAR_APP_CACHE 权限
public void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception e) {
// TODO: handle exception
}
}
public 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;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
最佳答案
在您的 list 中添加以下权限:
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
您还应该检查外部缓存目录。
public void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
File exDir = context.getExternalCacheDir();
if (exDir != null && exDir.isDirectory()) {
deleteDir(exDir);
}
} catch (Exception e) {
// TODO: handle exception
}
}
关于android - 如何在 Marshmallow 中以编程方式清除应用程序缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39991047/
概览 我正在使用 Flask-SqlAlchemy,现在我正在研究 marshmallow 来帮助我序列化和反序列化请求数据。 我能够成功: 使用 Flask-SqlAlchemy 创建我的模型 使用
我最近更新了我的应用程序以支持 android 6 marshmallow。我按照 https://developer.android.com/training/permissions/request
我正在尝试将 marshmallow-dataclass 与 marshmallow-oneofschema 结合起来以处理提供给我并用于连接 java 和 python 应用程序的数据结构。 在 J
marshmallow.Schema (v3.0+) 之间是否有区别,其中名称为 foo 的字段是使用 attribute="bar"< 定义的,另一个名称为 bar 的字段是用 data_key="
有没有办法在使用 Marshmallow - sqlalchemy 时避免将数据插入 session sqlalchemy marshmallow 避免加载到 session 中 引用:https:/
我想知道如何序列化嵌套Schema的字典。 天真地,我希望这样的语法能够工作: fields.List(Schema) fields.Dict(Schema) 或者也许 fields.List(fie
我需要创建一个与给定规范一致的棉花糖模式,其中我无法更改键名称。其中一个关键是 Python 中的保留关键字“from”。 class TemporalExtentSchema(Schema):
我正在使用 marshmallow 来验证 API 的数据。但是,它不适用于必填字段。 以下代码适用于长度验证。 password = fields.String(validate = validat
我正在为我的应用程序添加某些权限,例如允许访问相机,并且一切正常。但是当我最小化应用程序并禁用权限然后打开应用程序时,应用程序崩溃而不要求我重新启用权限(直到我关闭应用程序然后打开它)。我该如何修复此
我使用的是 nexus 6 android 6.0,仅针对 WRITE_EXTERNAL_STORAGE 权限对话框未显示,因为它正在显示其他危险权限。 final private int REQUE
我的 SMS 应用程序使用了一些危险的权限,例如发送 SMS、阅读联系人 等,我正在尝试为 android 6.0 测试新的权限系统但是当我在 Android 6.0 设备上安装它时,它已经授予这些权
我为 Marshmallow 设备集成了 READ PHONE STATE 的 Android Runtime Permission。此实现工作正常,弹出窗口显示在我的应用程序中,带有允许/拒绝选项。
我有这段代码允许用户访问相机拍照并从图库中选择图像,它适用于我运行 Android 5.1.1 的索尼 Xperia Z3。 我现在已经升级到运行 Android 6.0 的 Nexus 5X,但是当
您好,我想添加一个全局文本选择监听器,它显示任何选定文本的子菜单。 Android 6 通过新的文本选择监听器允许这样做。 是否可以通过外部应用程序使用此功能,然后填充子菜单? 最佳答案 这个概念被称
我希望开始使用 Marshmallow Fingerprint Authentication API。我明白要请求许可,我必须使用以下方法: ContextCompat.checkSelfPermis
我正在尝试像这样自定义我的搜索栏: 在 API 级别 我的style.xml: @drawable
在 Android Marshmallow 中有什么方法可以检测权限状态变化吗? 我还没有看到广播... 最佳答案 权限不能在应用程序中间更改。如果更改了权限 -> 应用程序将重新启动。没有广播 -
我在我们的团队中遇到了这个问题:我们想测试与日历的交互,显然我们需要日历写入权限才能执行此操作。有没有办法确保为仪器测试提供必要的权限?我知道您实际上可以授予对特定 avd 的权限,但是有更好的方法吗
我正在使用分析并在编译时收到此混淆警告: Warning: com.google.android.gms.internal.zzw$zza: can't find superclass or inte
RUN-TIME Permission 这样一个新的很棒的安全功能 我试图理解它并为此制作一个演示但是我想到了一个问题,即当我使用 DIALOG 处理用户权限时。 如何处理“不再询问” 假设我的应用程
我是一名优秀的程序员,十分优秀!