title: meteor cordova in-app apk update silently fails
body: <p>I am trying to implement an autoupdate functionality to distribute an app outside of the regular markets.
  I use a mix of cordova plugins in order to download and execute a newer version of my app.</p>
  
  <p>I can see that I download the apk to external storage, launch it, allow the installation but then nothing happens (it goes back to my original app).
  <a href="https://i.stack.imgur.com/ZdsbI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZdsbI.png" alt="apk update steps"></a></p>
  
  <p>I have a feeling that this is a permission issue, but I cannot see anything in the logs.
  <strong>If I open the downloaded apk from the filesystem, I can install it without any problems.</strong>
  This is ONLY when I launch the apk from the cordova app, the installation doesn't work.</p>
  
  <p>Here is the code I use to make the update:</p>
  
  <pre><code>/**
   * Begin the download and install of the update for android.
   */
  update() {
      let _this = this;
      let update = this._updateResult.get();
  
      // Check permissions first
      let permissions = cordova.plugins.permissions;
      let list = [permissions.WRITE_EXTERNAL_STORAGE];
  
      let errorPermissions = () =&gt; {
          sAlert.error("Cannot update permissions");
      };
  
      let successPermissions = () =&gt; {
          let fileTransfer = new FileTransfer();
  
          // let targetLocation = cordova.file.externalDataDirectory + "app.apk"; // better use externalCacheDirectory
          let targetLocation = "file:///storage/emulated/0/Download/"+"app-1.4.1.apk";
          console.debug("Begin update in appManager ", update);
          console.info("Download file", update.apk);
          console.info("Download to ", targetLocation);
  
          let onSuccess = (entry) =&gt; {
              let fileURL = entry.toURL();
              console.debug("download complete!", fileURL);
  
              cordova.plugins.fileOpener2.open(
                  fileURL,
                  'application/vnd.android.package-archive',
                  {
                      error: function (e) {
                          console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
                          _this._updating.set(false);
                      },
                      success: function () {
                          console.log('file opened successfully');
                          _this._updating.set(false);
                      }
                  }
              );
          }
          let onError = (error) =&gt; {
              _this._updating.set(false);
              console.log("download error source " + error.source);
              console.log("download error target " + error.target);
              console.log("download error code" + error.code);
          }
          let options = {
              chunkedMode: true,
              mimeType: "application/vnd.android.package-archive"
          };
  
          fileTransfer.download(
              encodeURI(update.apk),
              targetLocation,
              onSuccess,
              onError,
              options,
              true // trustAllHosts
          );
          fileTransfer.onprogress = (progressEvent) =&gt; {
              if (progressEvent.lengthComputable) {
                  let percent = Math.floor((progressEvent.loaded / progressEvent.total) * 100);
                  _this._updating.set(percent);
              } else {
                  _this._updating.set(true);
              }
          };
      }
  
      permissions.hasPermission(list,
          function (status) {
              console.debug("permissions status is", status);
              if (status.hasPermission) {
                  successPermissions();
              } else {
                  permissions.requestPermissions(
                      list,
                      function (status) {
                          if (!status.hasPermission) {
                              errorPermissions();
                          }
                          successPermissions();
                      },
                      errorPermissions
                  );
              }
          }, errorPermissions);
  }
  </code></pre>
  
  <p>I also tried to add other permissions like INSTALL_PACKAGES, DELETE_PACKAGES, RESTART_PACKAGES...</p>
  
  <p>I suppose the only important part of the code should be </p>
  
  <pre><code>cordova.plugins.fileOpener2.open(
                  fileURL,
                  'application/vnd.android.package-archive',
                  {
                      error: function (e) {
                          console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
                          _this._updating.set(false);
                      },
                      success: function () {
                          console.log('file opened successfully');
                          _this._updating.set(false);
                      }
                  }
              );
  </code></pre>
  
  <p>My logs show 'file opened successfully', any help much appreciated :)</p>