8

can i install apk in background using busybox on rooted device ???

i see something like that but it doesn't work

process install;
CommandCapture command = new CommandCapture(0, "chmod 777 /data/app");
RootTools.getShell(true).add(command).waitForFinish(); 
CommandCapture command2 = new CommandCapture(0, "chmod 777 /system/xbin/busybox");
RootTools.getShell(true).add(command2).waitForFinish();
install = Runtime.getRuntime().exec("/system/xbin/busybox install " + Environment.getExternalStorageDirectory() + "/Download/" + "xxx.apk /data/app/xxx.apk");
Omar Abdan
  • 1,901
  • 17
  • 29

3 Answers3

3

without using busybox

install = Runtime.getRuntime().exec("su");   
DataOutputStream os = new DataOutputStream(install.getOutputStream());  
os.writeBytes("pm install "+APKFile.apk+"\n");  
os.writeBytes("exit\n"); 
os.flush();
install.waitFor();
Omar Abdan
  • 1,901
  • 17
  • 29
2

It looks you use two paths for your busybox binary. First you chmod it in /system/xbin, but then you invoke it from system/bin. Ensure you use right path. And chmod 777 /data/app looks VERY BAD.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
1

If you run su -c pm install myapp.apk in a root shell, you should be able install in the background (note the 'pm') part. This has nothing to do with busybox, you can use any shell and you certainly don't need to change permission of /data/app.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • thank u for your answer but i want to install apk programmatically not from the shell – Omar Abdan Sep 27 '12 at 06:37
  • 1
    That is exactly what your cod above is trying to do: start a shell (`busybox`) with a command (`install`) and a parameter (`xxx.apk`). The problem is there is no such `install` command, you need to use `pm install`. Where did you copy this code from? Read their docs/readme to understand what it actually does. – Nikolay Elenkov Sep 27 '12 at 06:40
  • no there is install command in busybox that just copy the apk and put it in the /data/app only and when u restart the device installing start – Omar Abdan Sep 27 '12 at 06:49
  • Copying do `/data/app` is not the same as installing. Not sure what exactly the busybox command does, but do use the `pm` command if you really want to install it. In any case, what exactly is your problem? How does it 'not work'? Consider revising your original question and providing more details. – Nikolay Elenkov Sep 27 '12 at 07:16
  • Thank u @Nikolay i got it using pm install – Omar Abdan Sep 27 '12 at 08:30