gpt4 book ai didi

java - 反射清除Android应用程序缓存的方法

转载 作者:行者123 更新时间:2023-12-01 15:25:12 25 4
gpt4 key购买 nike

我正在尝试清除除我自己的应用程序之外的其他 Android 应用程序的应用程序缓存。为此,我在 PackageManager 类上使用反射。但是,每当我在调用方法之前初始化该方法时,它总是以 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为空,所以我的toast消息出现。有什么建议吗?

最佳答案

查看 Android 安全性文档:http://developer.android.com/guide/topics/security/security.html

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.

听起来系统会阻止你这样做(也通过反射)。

关于java - 反射清除Android应用程序缓存的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10262998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com