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()?

2 Answers 2

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

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>")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.