Thursday, February 9, 2012

Android Tutorial - Delete Batterystats.bin (Root Required)

If you have a rooted phone and can request Superuser permission then here is an easy way to delete your batterystats.bin file. This is the same as going into Recovery Mode and wiping battery stats.


In your OnCreate method call this...


//Request Superuser permission to use the application
      try {
    Runtime.getRuntime().exec("su");
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

Inside your Activity put this code on a button or OnClickListener...


                  Runtime runtime = Runtime.getRuntime();  
             Process proc = null;  
             OutputStreamWriter osw = null;  
             String command="busybox rm -f /data/system/batterystats.bin";    
             try {
             // Run Script        
             proc4 = runtime.exec("su");      
             osw4 = new OutputStreamWriter(proc.getOutputStream());
             osw4.write(command);              
             osw4.flush();      
             osw4.close();
                       }
             catch (IOException ex)
             {      
             ex.printStackTrace();
}
            }
        }

Now you are able to wipe your battery stats without going into recovery mode every time.

No comments:

Post a Comment