Android package manager - install and open APK
<p>I'm using this class to update my application programatically which works perfectly.</p>

<pre><code>public static class UpdateApp extends AsyncTask &lt; String, Void, Void &gt; {
 private Context context;
 public void setContext(Context contextf) {
  context = contextf;
 }

 @Override
 protected Void doInBackground(String...arg0) {
  try {
   URL url = new URL(arg0[0]);
   HttpURLConnection c = (HttpURLConnection) url.openConnection();
   c.setRequestMethod("GET");
   c.setDoOutput(true);
   c.connect();

   String PATH = "/mnt/sdcard/Download/";
   File file = new File(PATH);
   file.mkdirs();
   File outputFile = new File(file, "update.apk");
   if (outputFile.exists()) {
    outputFile.delete();
   }
   FileOutputStream fos = new FileOutputStream(outputFile);

   InputStream is = c.getInputStream();

   byte[] buffer = new byte[1024];
   int len1 = 0;
   while ((len1 = is.read(buffer)) != -1) {
    fos.write(buffer, 0, len1);
   }
   fos.close();
   is.close();

   String filename = "/mnt/sdcard/Download/update.apk";
   File filez = new File(filename);
   if (filez.exists()) {
    try {
     final String command = "pm install -r " + filez.getAbsolutePath();
     Process proc = Runtime.getRuntime().exec(new String[] {
      "su",
      "-c",
      command
     });
     proc.waitFor();
    } catch (Exception e) {
     e.printStackTrace();
    }
   }



  } catch (Exception e) {
   //Log.e("UpdateAPP", "Update error! " + e.getMessage());
  }
  return null;
 }
}
</code></pre>

<p>As you can see the class makes use of <code>"pm install"</code> command.</p>

<p>What I want to do is to run the updated app as soon as the installation is completed, so the user doesn't stay outside application. Is there any way I can achieve this through package manager or adb?</p>