反思方法来清除的Android应用程序缓存 [英] Reflecting methods to clear Android app cache
问题描述
我想清除其他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?
推荐答案
看一看的文档安全在Android:的 http://developer.android.com/guide/topics/security/security.html
Take a look at the docs for Security on Android: http://developer.android.com/guide/topics/security/security.html
在Android安全架构的核心设计的一点是,没有应用程序,默认情况下,必须执行,将其他应用程序,操作系统,或者用户造成不利影响的任何操作的权限。这包括读取或写入用户的私人数据(如联系人或电子邮件),读取或写入其他应用程序的文件,访问网络,保持清醒的设备等。
A central design point of the Android security architecture is that no application, by default, has permission to perform any operations that would adversely impact other applications, the operating system, or the user. This includes reading or writing the user's private data (such as contacts or e-mails), reading or writing another application's files, performing network access, keeping the device awake, etc.
这听起来像系统会阻止你做这个(通过反射太)。
It sounds like the system will block you from doing this (through reflection too).
这篇关于反思方法来清除的Android应用程序缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!