4

I want to run an executable on a non-rooted android device.

Using the following commands in java

Runtime.getRuntime().exec("/bin/chmod 744 /data/data/com.example.myapp/myBin");
Runtime.getRuntime().exec("/data/data/com.example.myapp/myBin");

results in

Error running exec(). Command: [/data/data/com.example.myapp/myBin] 
    Working Directory: null Environment: null

I found alot of questions on this but no answer that worked in my case. How can I execute the binary file correctly?

user2212461
  • 3,105
  • 8
  • 49
  • 87

2 Answers2

3

If you are running this from a service (and not a app activity), you will have to set the permissions as 777.

Shashank Singla
  • 1,797
  • 17
  • 13
1
Runtime.getRuntime().exec("/bin/chmod 744 /data/data/com.example.myapp/myBin");

While it may not be your only problem, on most builds of Android chmod lives in /system/bin and there is no /bin directory, so your failure is likely actually on the attempt to execute a non-existent tool, even before getting to your custom binary.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117