Android 清除数据

利用反射机制清除数据:设置->应用程序->应用名->

准备条件:

IPackageDataObserver.aidl 

IPackageStatsObserver.aidl

PackageStats.aidl

清除数据:

ActivityManager am = (ActivityManager)
                getActivity().getSystemService(Context.ACTIVITY_SERVICE);
am.clearApplicationUserData(packageName, mClearDataObserver);

清除缓存:

Method getPackageSizeInfo = pm.getClass().getMethod("getPackageSizeInfo", String.class, IPackageStatsObserver.class);     
            List<ApplicationInfo> application = new ArrayList();  
            application = pm.getInstalledApplications(0);  
            for(int i=0;i<application.size();i++)  
            {  
                ApplicationInfo app = application.get(i);  
                getPackageSizeInfo.invoke(pm, app.packageName,  new IPackageStatsObserver.Stub()   
                {     
                    @Override    
                    public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException   
                    {     
                        if(pStats.cacheSize != 0)  
                        {  
                            cacheSize += pStats.cacheSize;  
                            Log.e(TAG, "cacheSize: " + pStats.packageName + "  ;" + pStats.cacheSize);   
                        }  
                    }     
                });  
            }

  

相关推荐