0

I have a java file that have this piece of code to list the files in the cache directory of an app and it works well.

 String command[] = {"adb","shell","run-as",pack,"ls","cache/"};
 Process process = Runtime.getRuntime().exec(command);
 InputStream o_out = process.getInputStream(); //covert o_out to String to get the files name

Now i want to this code to run on directly on android devices, but it fails because the command was wrong, any idea?

Quang Nhat
  • 135
  • 1
  • 8
  • What is the exect command that you are using? What is the response or the error? – TDG Aug 24 '18 at 09:49
  • please explain, why it is required to use shell command in the given situation. this would be possibly be a `java` question then, but not exactly an `android` question. – Martin Zeitler Aug 24 '18 at 10:58
  • Maybe this is a part of your problem solution: https://stackoverflow.com/a/22985070 – Dvoliq Aug 24 '18 at 11:11

1 Answers1

-1

Try this:

String command[] = {"run-as",pack,"ls","cache/"};
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
贾亚光
  • 201
  • 1
  • 5
  • Still not work, but thanks anw, i think i can get the internal file within the app without using process. – Quang Nhat Aug 24 '18 at 09:12
  • 3
    "Try this" aka random guess answers are not useful because they don't show why this should work and how it should be adapted if it doesn't work (as in your case). Please consider adding some explanation text. – ivan_pozdeev Aug 24 '18 at 11:02