En algunos dispositivos Android, en el shell ADB, solo puedo ejecutar echo
, cd
, ls
. Cuando corro:¿Cómo puedo ejecutar comandos de Linux en un dispositivo Android?
tar -cvf //mnt/sdcard/BackUp1669/apk/test.tar /mnt/sdcard/test.apk
o el comando cp
, devuelve:
sh: tar: not found
¿Por qué no puedo ejecutar estos comandos? Algunos dispositivos admiten estos comandos. Mi objetivo final es copiar un archivo de la carpeta /data/data a la tarjeta SD. Tengo Do y tengo el siguiente código:
int timeout = 1000;
String command = "tar -cvf /" + Environment.getExternalStorageDirectory() + "/cp/"
+ packageName + ".tar" + " " + path;
DataOutputStream os = new DataOutputStream(process.getOutputStream());
BufferedReader is = new BufferedReader(new InputStreamReader(new DataInputStream(
process.getInputStream())), 64);
String inLine;
try {
StringBuilder sbCommand = new StringBuilder();
sbCommand.append(command).append(" ");
sbCommand.append("\n");
os.writeBytes(command.toString());
if (is != null) {
for (int i = 0; i < timeout; i++) {
if (is.ready())
break;
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (is.ready()) {
inLine = is.readLine();
} else {
}
}
} catch (IOException e) {
e.printStackTrace();
}
Se detiene siempre en is.ready()
, y cuando lo cambié a process.waitfor()
también se detuvo. ¿Por qué?
¿Te das cuenta de que el shell de Android es mucho más restringido que un sistema operativo Linux estándar, verdad? – JoxTraex