Android 清除指定应用缓存

时间:2025-01-27 08:01:36

/**

* 清除指定应用缓存,即删除data/data/packageName/cache目录下文件

* @param mContext

* @param packageName

*/

public void clearCache(final Context mContext,final String packageName){

(new Thread(){

@Override

publicvoid run() {

try {

Context otherAppContext = (packageName, Context.CONTEXT_IGNORE_SECURITY);

File path = ();

if(path ==null)

return;

// #rm -r xxx   删除名字为xxx的文件夹及其里面的所有文件

String killer =" rm -r " + ();

Process p = ().exec("su");

DataOutputStream os =new DataOutputStream(());

(() +"\n");

("exit\n");

();

} catch (NameNotFoundException e) {

//TODO Auto-generated catch block

();

} catch (IOException e) {

//TODO Auto-generated catch block

();

}

}

}).start();

}

相关文章