反思方法来清除的Andr​​oid应用程序缓存

我想清除其他Android应用程序的应用程序缓存,除了我自己。要做到这一点,我使用的软件包管理系统类的反映。但是,每当我初始化方法之前我调用它,它总是最终被空。

I am trying to clear the app cache of other android apps besides my own. To do this, I am using reflection on the PackageManager class. However, whenever I initialize the method before I invoke it, it always ends up being null.

    private  void initiateClearUserData() {
    // Invoke uninstall or clear user data based on sysPackage
    String thePackageName;
    PackageManager pm = speedy.this.getPackageManager();
    List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);
    ApplicationInfo ai;// = installedApps.get(0);
    ActivityManager.RunningAppProcessInfo process;
    for(int x=0; x<4; x++){
        ai = installedApps.get(x);

下面是我的问题是:

        thePackageName = ai.packageName.toString();// mAppEntry.info.packageName;
        Method deleteApplicationCacheFiles = null;
        mClearCacheObserver = new ClearCacheObserver();
    try {
        deleteApplicationCacheFiles = pm.getClass().getMethod(
             "deleteApplicationCacheFiles", String.class, PackageManager.class);
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
 if(deleteApplicationCacheFiles!= null){
     try {
        deleteApplicationCacheFiles.invoke(thePackageName, mClearCacheObserver);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }else{
    Toast.makeText(speedy.this, "Hell naw",
            Toast.LENGTH_SHORT).show();
    }
    }
}

由于方法deleteApplicationCacheFiles为空,我敬酒的消息显示出来。有什么建议?

Because Method deleteApplicationCacheFiles is null, my toast message shows up. Any suggestions?



 1 条回答