public void installApp(UpdatesResponse.UpdateApk apk) {

    Download download = new Download();
    download.setId(apk.hashCode());
    download.setName(apk.name);
    download.setPackageName(apk.packageName);
    download.setVersion(apk.versionName);
    download.setMd5(apk.md5sum);

    String icon = apk.icon;

    if (icon != null && icon.contains("_icon")) {
      String[] splittedUrl = icon.split("\\.(?=[^\\.]+$)");
      String iconSize = IconSizeUtils.generateSizeString(this);
      icon = splittedUrl[0] + "_" + iconSize + "." + splittedUrl[1];
    }

    download.setIcon(icon);

    startDownloadFromV6(download, apk);
  }
  public void startDownloadFromAppId(final long id) {
    startService(new Intent(getApplicationContext(), DownloadService.class));

    if (mBuilder == null) mBuilder = createDefaultNotification();
    startForeground(-3, mBuilder.build());

    final SpiceManager manager = new SpiceManager(AptoideSpiceHttpService.class);
    if (!manager.isStarted()) manager.start(getApplicationContext());
    final String sizeString = IconSizeUtils.generateSizeString(getApplicationContext());

    new Thread(
            new Runnable() {
              @Override
              public void run() {

                Cursor apkCursor = new AptoideDatabase(Aptoide.getDb()).getApkInfo(id);

                if (apkCursor.moveToFirst()) {

                  String repoName = apkCursor.getString(apkCursor.getColumnIndex("reponame"));
                  final String name = apkCursor.getString(apkCursor.getColumnIndex("name"));
                  String package_name =
                      apkCursor.getString(apkCursor.getColumnIndex("package_name"));
                  final String versionName =
                      apkCursor.getString(apkCursor.getColumnIndex("version_name"));
                  final int versionCode =
                      apkCursor.getInt(apkCursor.getColumnIndex("version_code"));
                  final String md5sum = apkCursor.getString(apkCursor.getColumnIndex("md5"));
                  String icon = apkCursor.getString(apkCursor.getColumnIndex("icon"));
                  final String iconpath = apkCursor.getString(apkCursor.getColumnIndex("iconpath"));

                  GetApkInfoRequestFromVercode request =
                      new GetApkInfoRequestFromVercode(getApplicationContext());

                  request.setRepoName(repoName);
                  request.setPackageName(package_name);
                  request.setVersionName(versionName);
                  request.setVercode(versionCode);

                  Download download = new Download();
                  download.setId(md5sum.hashCode());
                  download.setName(name);
                  download.setPackageName(package_name);
                  download.setVersion(versionName);
                  download.setMd5(md5sum);

                  if (icon.contains("_icon")) {
                    String[] splittedUrl = icon.split("\\.(?=[^\\.]+$)");
                    icon = splittedUrl[0] + "_" + sizeString + "." + splittedUrl[1];
                  }

                  download.setIcon(iconpath + icon);

                  manager.getFromCacheAndLoadFromNetworkIfExpired(
                      request,
                      repoName + md5sum,
                      DurationInMillis.ONE_HOUR,
                      new DownloadRequest(download.getId(), download));
                  apkCursor.close();
                }
              }
            })
        .start();
  }