title: Installing an Android apk programmatically as part of a test framework
body: <p>I'm attempting to install an apk programmatically, but I'm not having much luck. I'm setting up an automated test framework targeting physical devices, and I want to have the test devices retrieve the latest apk from the build server before running tests. While I am aware that there is no general way to actually install an apk without the user's consent, I'm curious if there might be some approach available in the case where a developer owns both the apk and device.  </p>
  
  <p>Approaches I've tried in the past (the apk has been downloaded to pathName/apkFilename):</p>
  
  <pre><code>String command = "adb install " + pathName + apkFilename;
  Runtime.getRuntime().exec(command);
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.setDataAndType(Uri.fromFile(new File(pathName + apkFilename)), "application/vnd.android.package-archive");
  getActivity().startActivity(intent);
  </code></pre>
  
  <p>While I haven't been able to get the first approach to work, the second attempt creates a system dialog asking the user to confirm the installation (so almost there, but not quite). Since it is a System dialog, I, unfortunately, cannot use Robotium to confirm.</p>