2

OK,

I know there are are a fair number of questions similar to this, but non have given me the answer I'm looking for.

I have a custom rooted ROM (without play store). It's a android stick pc (So I don't have the system key to sign my app with, unless I've missed something in the kernel docs). I want my app to check nightly for updates from my server. If there is a new version I want it to download and install it without user interaction.

I know I can trigger the update screen with

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(pathToApk));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);

But as I said it's not what I want. SU and busybox are on the device. Anyone know of a way to do this?

Pyromanci
  • 527
  • 9
  • 21
  • you should have the system key if you compiled your custom rom. Also, you need to use the PackageManager to install apps, if I recall correctly. You'd need to develop a private api to install your apps, as this is not really supported out of the box. – njzk2 Apr 09 '14 at 17:22
  • It's not a completely custom compile. Since I have to translate alot of the read me and other doc files (as i apear to be missing something since it wont completely compile), I have I just took the original system images and modified them (boot animations, build.props, ect). – Pyromanci Apr 09 '14 at 17:38

1 Answers1

3

You can access the PackageManager from the command line using pm. If su is present, you need to run

su pm install pathToApk.apk

To run it from a Java application, use ProcessBuilder.

njzk2
  • 38,969
  • 7
  • 69
  • 107
  • I tired this, but it didn't install and there was no output. Here is the code that i executed. http://pastebin.com/Bz1EiXQc – Pyromanci Apr 09 '14 at 19:50
  • you probably need to read the stderr as well to figure out the reason for the error (call `redirectErrorStream(true)` on your `pb`) – njzk2 Apr 09 '14 at 19:55
  • Also, since this is a shell command, you can also try to run it from an adb shell to test it. – njzk2 Apr 09 '14 at 19:56
  • I got it to work from the adb shell, but still couldn't get it to work through the code. Here is my process that worked through. http://pastebin.com/8LXJ15is – Pyromanci Apr 09 '14 at 20:27
  • a few answers on the same topic : http://stackoverflow.com/questions/14398543/android-install-apk-silently-by-busybox-command-line – njzk2 Apr 09 '14 at 20:35
  • I changed it to just fire off su and then write the pm command to the process's output stream and that worked. – Pyromanci Apr 09 '14 at 20:44
  • @Pyromanci could you post the code that worked. I am struggling with the same problem this very minute. – Gichamba May 01 '14 at 13:45
  • Sorry, I no longer have this code (this question was from over a year ago). If you look at njzk2 last comment. The second section of code in the question was basically what I did at the time. Though I no longer do it this way as the App I was doing this with has become a System App in the Custom Rom I was working on and is now updated via OTA updates. – Pyromanci May 08 '15 at 15:03