您正在刪除/ data/data及其所有子目錄。這是應用程序存儲應用程序私有數據的地方,SuperUser肯定會在這裏存儲授權應用程序的列表。
我相信你已經猜到了什麼是異想天開......你正在刪除自己的授權。
您需要向superUser添加一個異常。
要添加一個異常,我找不到一個簡單的解決方案,因爲只有有限的shell命令可用。如果你安裝了busybox,它會給你機會使用grep命令來解析輸入並排除你想要的行。
另外,程序可以用下面的方法做:
process = Runtime.getRuntime().exec(new String[] {"su", "-c", "ls /data/data"});
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
ArrayList<String> files = new ArrayList<String>();
files.add("su");
files.add("-c");
files.add("rm -r");
while ((line = bufferedReader.readLine()) != null){
//test if you want to exclude the file before you add it
files.add("/data/data/" + line);
}
//issue a new command to remove the directories
process = Runtime.getRuntime().exec(files.toArray(new String[0])); //changed this line
希望它幫助。
--EDITED--
代碼波紋管有根設備上工作的罰款。最後發出的命令也是ls
,因爲我不想刪除我的文件,但您可以用其他任何東西替換它(請參閱文件中的註釋)。
private void execCmd(){
Process process;
try {
process = Runtime.getRuntime().exec(new String[] {"su", "-c", "ls /data/data"});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
ArrayList<String> files = new ArrayList<String>();
files.add("su");
files.add("-c");
// files.add("rm -r"); //Uncomment this line and comment the line bellow for real delete
files.add("ls");
try {
while ((line = bufferedReader.readLine()) != null){
//test if you want to exclude the file before you add it
files.add("/data/data/" + line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//comment lines bellow to stop logging the command being sent
Log.d(TAG, "Command size: " + files.size());
for(int i=0; i< files.size(); i++)
Log.d(TAG, "Cmd[" + i + "]: " + files.get(i));
try {
process = Runtime.getRuntime().exec(files.toArray(new String[0]));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //changed this line
}
問候
答案時是有幫助的我的問題,然後我接受了,但我會是「少」難以接受的答案現在... – CELB