我想将文件从data/data/mypackage
复制到/mnt/sdcard
但是当我应用命令行时没有发生任何事情。我的手机已经植根了,我已经渗透了这个命令。我有数组列表并在获取所有命令“getCommandsToExecute()
”方法后将所有命令放入此数组中并应用我的所有命令:
public final boolean execute() {
boolean retval = false;
try {
ArrayList<String> commands = getCommandsToExecute();
if (null != commands && commands.size() > 0) {
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
suProcess.getOutputStream());
// Execute commands that require root access
for (String currCommand : commands) {
os.writeBytes(currCommand + "\n");
os.flush();
}
os.writeBytes("exit\n");
os.flush();
try {
int suProcessRetval = suProcess.waitFor();
if (255 != suProcessRetval) {
// Root access granted
retval = true;
} else {
// Root access denied
retval = false;
}
} catch (Exception ex) {
Log.e("ROOT", "Error executing root action", ex);
}
}
} catch (IOException ex) {
Log.w("ROOT", "Can't get root access", ex);
} catch (SecurityException ex) {
Log.w("ROOT", "Can't get root access", ex);
} catch (Exception ex) {
Log.w("ROOT", "Error executing internal operation", ex);
}
return retval;
}
我的数组列表中包含以下命令:
ArrayList<String> hi= new ArrayList<String>();
hi.add("shell cp /data/data/com.askfm/databases /mnt/sdcard");