Here, cleanup is to clean the cache of other programs in the software, there are two types. Reflection is used in all aspects of the knowledge, there is no way, Android system API to hide these methods. Reflection will not be said, do not know yourself Baidu, Google!
One type with root permission:
Class C1 = Class. forname ("android. content. PM. ipackagedataobserver ");
Method method = PM. getclass (). getmethod ("deleteapplicationcachefiles", String. Class, ipackagedataobserver. Class );
Method. Invoke (PM, packagename, new ipackagedataobserver. Stub (){
@ Override
Public void onremovecompleted (string packagename,
Boolean succeeded) throws RemoteException {
// Todo auto-generated method stub
}
});
<Uses-Permission Android: Name = "android. Permission. delete_cache_files"/>
In addition, you do not need permissions. one-click cleanup:
Private Static long getenvironmentsize ()
{
File localfile = environment. getdatadirectory ();
Long L1;
If (localfile = NULL)
L1 = 0l;
While (true)
{
String STR = localfile. getpath ();
Statfs localstatfs = new statfs (STR );
Long L2 = localstatfs. getblocksize ();
L1 = localstatfs. getblockcount () * L2;
Return L1;
}
}
Packagemanager PM = activity. getpackagemanager ();
Class [] arrayofclass = new class [2];
Class localclass2 = long. type;
Arrayofclass [0] = localclass2;
Arrayofclass [1] = ipackagedataobserver. Class;
Method localmethod = PM. getclass (). getmethod ("freestorageandpolicy", arrayofclass );
Long locallong = long. valueof (getenvironmentsize ()-1l );
Object [] arrayofobject = new object [2];
Arrayofobject [0] = locallong;
Localmethod. Invoke (PM, locallong, new ipackagedataobserver. Stub (){
Public void onremovecompleted (string packagename, Boolean succeeded) throws RemoteException {
// Todo auto-generated method stub
}});
Permission: <uses-Permission Android: Name = "android. Permission. clear_app_cache"/>
This is also a little bit of insight, but it is not very mature. I hope you can learn more about the shortcomings or mistakes.
If ipackagedataobserver cannot be imported, write ipackagedataobserver. aidl as follows:
Package Android. content. PM;
/**
* API for package data change related callbacks from the package manager.
* Some usage scenarios include deletion of cache directory, generate
* Statistics related to code, Data, Cache Usage (Todo)
*{@ Hide}
*/
Oneway interface ipackagedataobserver {
Void onremovecompleted (in string packagename, Boolean succeeded );
} Put It In The SRC package.