title: Programmatically download APK from Google Drive doesn't work
body: <p>When finding random apk's online through urls, I can successfully download and install them, the user is prompted to ask if they want to install comes up. But when I upload the same apk's to Google drive, and then run the download url from Google drive, the apk's doesn't work. I get a <em>"There was a problem while parsing the package"</em> on the device screen. I put a log to see how much data is being downloaded. And it appears that the apk's being downloaded from google drive are barely the size of what the apk's should be. Around 50k instead of 4MB. I see a lot of questions online about this, but none have talked about Google play not sending the full file. Is there something I'm missing in order to get the full apk downloaded from Google drive? here is the code, </p>
  
  <pre><code>private void downloadApk(){
  
    //  checkVersion();
      String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
      File folder = new File(extStorageDirectory);
      folder.mkdirs();
      File file = new File(folder, "app-debug.apk");
      try {
          file.createNewFile();
      } catch (IOException e1) {
          e1.printStackTrace();
      }
      DownloadApkTask downloadApkTask = new DownloadApkTask(APKURL,file);
      downloadApkTask.execute();
  }
  
  public class DownloadApkTask extends AsyncTask&lt;String, Void, Void&gt; {
  
      String fileURL;
      File directory;
      public DownloadApkTask(String fileURL,File directory) {
          this.fileURL = fileURL;
          this.directory = directory;
      }
  
      @Override
      protected Void doInBackground(String... params) {
  
          Log.v("DO in Back started","Started");
          try {
  
              FileOutputStream f = new FileOutputStream(directory);
              URL u = new URL(fileURL);
              HttpURLConnection c = (HttpURLConnection) u.openConnection();
              c.setRequestMethod("GET");
              c.connect();
              InputStream in = c.getInputStream();
              byte[] buffer = new byte[1024];
              int len1 = 0;
              while ((len1 = in.read(buffer)) &gt; 0) {
                  Log.v("PROGREsS", String.valueOf(len1));
                  f.write(buffer, 0, len1);
              }
              f.close();
              directory.setReadable(true,false);
          } catch (Exception e) {
              System.out.println("exception in DownloadFile: --------"+e.toString());
              e.printStackTrace();
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void stringReturn) {
          super.onPostExecute(stringReturn);
          File file = new   File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/app-debug.apk");
  
          Log.v("STARTING INSTALLATION","-----");
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
          startActivity(intent);
  
      }
  }
  </code></pre>