清除棉花糖以上OS版本上的缓存 [英] Clearing the Cache on OS Versions above Marshmallow

查看:107
本文介绍了清除棉花糖以上OS版本上的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个Android应用程序,该应用程序将清除其他应用程序的缓存.我想出了如何在棉花糖下的Android版本中做到这一点.

I want to make an Android App which will clean the cache of other apps. I have figured out how to do that for Android Version below Marshmallow.

This is what I am using for Android Honeycom and above:

    if (isExternalStorageWritable()) {
        final File externalDataDirectory = new File(Environment
                .getExternalStorageDirectory().getAbsolutePath(), "/Android/data");

        final String externalCachePath = externalDataDirectory.getAbsolutePath() +
                "/%s/cache";

        if (externalDataDirectory.isDirectory()) {
            final File[] files = externalDataDirectory.listFiles();

            for (File file : files) {
                if (!deleteDirectory(new File(String.format(externalCachePath,
                        file.getName())), true)) {
                    Log.e(TAG, "External storage suddenly becomes unavailable");

                    return false;
                }
            }
        } else {
            Log.e(TAG, "External data directory is not a directory!");
        }
    } else {
        Log.d(TAG, "External storage is unavailable");
    }

但是我在解决如何使用Android版本棉花糖及更高版本上遇到问题.

But I am having an issue to figure out how to do it for Android Version Marshmallow and above.

市场上存在的其他缓存清理器是否能够通过获得可访问性许可或任何其他方式来执行此操作?

Other cache cleaners present in the market are able to perform this by taking accessibility permission or any other way?

推荐答案

从Android 6.0(棉花糖)开始,不允许任何普通应用清除其他应用的缓存.仅当您的应用程序是系统应用程序或由与系统签名相同的证书签名时,才可以清除其他应用程序的缓存.但是,如何使用却存在一些漏洞.

Starting from Android 6.0 (Marshmallow) any normal app is not permitted to clear the cache of other apps. You can clear the cache of other apps only if your app is a system app or is signed by the same certificate the system is signed. But there is a hack on how you can.

您可以使用可访问性服务(由您正确指向)来执行此操作.

You can perform this by using accessibility service(which is correctly pointed by you).

AFAIK,您可以显示缓存值,然后询问用户可访问性权限,并在授予权限后打开设置屏幕->进入存储->单击缓存"按钮,然后按确定.

AFAIK you can show the cache value and then ask the user for the accessibility permission and after the permission is granted open the settings screen-->go to storage-->click the Cache button and then press ok.

请记住,这只是黑客行为,并且可能会因各种OEM和Android版本而产生错误.

Keep in mind that this is only a hack and may produce errors based on various OEM's and Android version.

关于如何实现,是探讨无障碍服务如何可以的很好的例子被使用.

Coming to how you can achieve, this is a very good example to explore how accessibility service can be used.

此外,请记住,您需要先获得GOOGLE PLAY的批准才能使用可访问性,否则可能会从PLAY商店中删除该应用.在提供更新之前进行许可,否则他们可能会暂停或终止您的应用程序.对此请务必小心.

ALSO, KEEP IN MIND THAT YOU NEED TO TAKE PRE APPROVAL FROM GOOGLE PLAY TO USE ACCESSIBILITY OR ELSE THE MIGHT REMOVE THE APP FROM THE PLAY STORE. DO TAKE PERMISSION BEFORE GIVING AN UPDATE OR ELSE THEY MIGHT SUSPEND OR TERMINATE YOUR APP. BE VERY CAREFUL ABOUT THIS.

这篇关于清除棉花糖以上OS版本上的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆