0

I need to run a test suite using monkeyrunner. Is there a way to clear the app cache after running some tests other than monkey.device.uninstall()?

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130

2 Answers2

0

to clear your cache use the following line of code.

File dir = context.getCacheDir(); 
    if (dir != null && dir.isDirectory()) { 
     deleteDir(dir); 
    } 


    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(); 
   }

for more detail http://grabcodes.blogspot.com

coading fever
  • 221
  • 2
  • 10
0

You can use adb command to remove the cache folder of app like below. You should know the folder path for that app. For facebook app,

adb shell
cd /Android/data/com.facebook.katakana/cache
rm *
exit

This clears the cache. If your using monkeyrunner then from jython code you can use

subprocess.call("<above mentioned commands>")
Vinayak Kolagi
  • 1,831
  • 1
  • 13
  • 26