Answers
你指的是删除其他应用的数据吗?如果是的话,先停止该应用,再删
public void deleAppData(String packageName) {
PackageManager packageManager = mContext.getPackageManager();
packageManager.clearApplicationUserData(packageName, new IPackageDataObserver.Stub() {
public void onRemoveCompleted(String arg0, boolean arg1)
throws RemoteException {
}
});
}
熊猫猫lx
answered 10 years, 2 months ago
java
PackageManager pm = context.getPackageManager(); Class[] arrayOfClass = new Class[2]; Class localClass2 = Long.TYPE; arrayOfClass[0] = localClass2; arrayOfClass[1] = IPackageDataObserver.class; Method localMethod = pm.getClass().getMethod( "freeStorageAndNotify", 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 { } });
关键代码在这里了,没别的,自己try,catch一下。
另外,这是清除所有程序的缓存的。若想清除指定应用缓存是必须root的,否则你就跳应用详情页让用户手动清除吧。
我就是⑨~
answered 10 years, 2 months ago