相关疑难解决方法(0)

如何删除Android M中所有应用的应用缓存?

是否可以选择删除Android M中所有应用或某些应用的缓存?

似乎大多数方式在Android M中不再起作用了.

作为参考,我在本讨论中使用了此代码: Android:清除所有应用程序的缓存?

PackageManager  pm = getPackageManager();
// Get all methods on the PackageManager
Method[] methods = pm.getClass().getDeclaredMethods();
for (Method m : methods) {
    if (m.getName().equals("freeStorage")) {
        // Found the method I want to use
        try {
            long desiredFreeStorage = 8 * 1024 * 1024 * 1024; // Request for 8GB of free space
            m.invoke(pm, desiredFreeStorage , null);
        } catch (Exception e) {
            // Method invocation failed. Could be a permission problem
        }
        break;
    }
} 
Run Code Online (Sandbox Code Playgroud)

结合此权限 …

android caching delete-file

10
推荐指数
1
解决办法
5333
查看次数

如何从我们的Android应用程序删除其他应用程序缓存?

我正在尝试开发一个可以删除其他应用程序缓存数据的Android应用程序,我试图浏览所有博客,但它们都没有为我工作,我可以通过以下代码清除我的应用程序的缓存

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));
                        Toast.makeText(DroidCleaner.this, "Cache Cleaned", Toast.LENGTH_LONG).show();
                        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 …
Run Code Online (Sandbox Code Playgroud)

android caching

7
推荐指数
1
解决办法
1万
查看次数

如何清除Android应用缓存?

我正在编写一个应用程序,可以编程方式清除设备上安装的所有第三方应用程序的应用程序缓存.以下是Android 2.2的代码段

public static void trimCache(Context myAppctx) {

    Context context = myAppctx.createPackageContext("com.thirdparty.game", 
            Context.CONTEXT_INCLUDE_CO|Context.CONTEXT_IGNORE_SECURITY);

    File cachDir = context.getCacheDir();        
    Log.v("Trim", "dir " + cachDir.getPath());

    if (cachDir!= null && cachDir.isDirectory()) {

        Log.v("Trim", "can read " + cachDir.canRead());
        String[] fileNames = cachDir.list();
        //Iterate for the fileName and delete
    }
}
Run Code Online (Sandbox Code Playgroud)

我的清单有以下权限:

android.permission.CLEAR_APP_CACHE
android.permission.DELETE_CACHE_FILES

现在的问题是打印了缓存目录的名称,但文件列表cachDir.list()始终返回null.我无法删除缓存目录,因为文件列表始终为null.

还有其他方法可以清除应用程序缓存吗?

android

6
推荐指数
1
解决办法
2万
查看次数

以编程方式清除应用缓存?

我想编写一个实用程序,用户可以选择一组已安装的应用程序并清除其数据缓存,例如您可以使用内置的"设置" - >"应用程序"设置屏幕和"清除缓存"按钮手动执行此操作.

如何访问每个应用程序拥有的缓存数据量并以编程方式清除这些缓存?

java mobile android

4
推荐指数
2
解决办法
6672
查看次数

标签 统计

android ×4

caching ×2

delete-file ×1

java ×1

mobile ×1