title: Android: why Download-Manager automatically run (downloaded) apk-file in android?
body: <p>The problem is, after I download .apk-file from server using this method:</p>
  
  <pre><code>public void Update(String apkName) {
      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
  
      File file = new File("/sdcard/Download/"+ apkName + ".apk");
      if (file.exists()) {
          file.delete();
      }
  
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/", apkName + ".apk");       
      DownloadManager manager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
      manager.enqueue(request);
  }
  </code></pre>
  
  <p>then I use BroadCastReciever to take install-action when the download-operation is complete as follows:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  // some codes here...
  
  BroadcastReceiver receiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              String action = intent.getAction();
  
              if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)){
                  Intent i = new Intent(Intent.ACTION_VIEW);
                  i.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Download/" + apkName + ".apk")),
                          "application/vnd.android.package-archive");
                  startActivity(i);
              } else {
  
              }
  
          }
      };
  
      getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
  
      download_apk(apkName);
      return rootView;
  }
  </code></pre>
  
  <p>Now problem is when the download-opration is complete DownloadManager try to install apk-file and I get <a href="http://jalaldoth.persiangig.com/image/device-2015-07-14-120426.png" rel="nofollow">this</a> which is "Parse Error/There is a Problem parsing the package".</p>
  
  <p>after I click OK, true Install-page shows up (which is triggered by broadcastReciever).</p>
  
  <p>I run this proccess in Activity and it was perfectly fine. As you see above this time it is in Fragment! is this could be the reason??</p>
  
  <p>How can I stop DownloadManager from running apk Automatically?
  can anybody help me out?</p>