Clear data of another application in Root device

I am developing an app in which i want to clear data of another application.

I tried following way:
1. runtime.exec("pm clear packageName");


  public void clearApplicationData(String packageName) {
                File f = getApplicationContext().getFilesDir();
                String path = f.getAbsolutePath();
                String newPath = path.replace("com.example.demoapp", packageName);
                File appDir = new File(newPath );


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

I want to do this in rooted device. but not able to do that.
Also in second option i replacing packageName( another app package name) with my package, so that i can get all the directory of another package. but it not allow me to delete or read sub directory or any thing in another package in root device.

In second option,as of now i am only using getFilesDir() for general purpose. if this would be work then i am able to delete other directory also.

Please help me out of this.

Thank you in advanced !!

Source: New Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.