title: Installing apk on android device via ADB with Java program on Linux
body: <p>I am trying to pass a path from Java's inbuilt file manager to ADB with java program on Linux to install apk on android device. When the code is executed the apk selected using file manager never gets installed.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>JFileChooser chooser = new JFileChooser();
  FileNameExtensionFilter filter = new FileNameExtensionFilter(
          "APK Files", "apk");
  chooser.setFileFilter(filter);
  int returnVal = chooser.showOpenDialog(getParent());
  if(returnVal == JFileChooser.APPROVE_OPTION) {
      System.out.println("You choose to open this file: " + chooser.getSelectedFile().getName());
      File file = new File("");
      System.out.println(file.getAbsolutePath().toString());
  
      try {
          Process p1 = Runtime.getRuntime().exec("adb kill-server"); //for killing old adb instance
          Process p2 = Runtime.getRuntime().exec("adb start-server");
          Process p3 = Runtime.getRuntime().exec("adb install \"" + file.getAbsolutePath() + "\"");
          p3.waitFor();
          Process p4 = Runtime.getRuntime().exec("adb kill-server");
      } catch (Exception e1) {
  
          System.err.println(e1);
      }
  </code></pre>
  
  <p>The following code should install the apk:</p>
  
  <pre><code>Process p3 = Runtime.getRuntime().exec("adb install \"" + file.getAbsolutePath() + "\"");
  </code></pre>