title: Open File PDF automatically After Download Completed
body: <p>I have a problem. I have code for download and open file PDF. I want after download completed, PDF will open automatically.</p>
  
  <p>This is my code for download pdf file :</p>
  
  <pre><code>  private EditText ids;
    private TextView no;
    private TextView per;
    private EditText surat_fi;
    private EditText disp;
    private Button kepada, baca;
  
    Context context=this;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.suratmasuk);
  
          ids = (EditText) findViewById(R.id.edid);
          no = (TextView) findViewById(R.id.ednomor);
          per = (TextView) findViewById(R.id.edperihal);
          surat_fi = (EditText) findViewById(R.id.surat);
          disp = (EditText) findViewById(R.id.eddisposisi);
  
    ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
    JSONObject json = JSONSuratMasuk.getJSONfromURL("http://link...");
  
          try{
          JSONArray  data = json.getJSONArray("data");
  
          for(int i=0;i&lt;data.length();i++){
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          JSONObject jsonobj = data.getJSONObject(i);
  
                 map.put("id1",  jsonobj.getString("id"));
                 map.put("nomor",  jsonobj.getString("nosurat"));
                 map.put("perihal", jsonobj.getString("perihal"));
                 map.put("surat", jsonobj.getString("surat"));
          mylist.add(map);
   }
          }catch(JSONException e)        {
          Log.e("log_tag", "Error parsing data "+e.toString());
   }
  
                ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.row,
                new String[] { "nomor", "perihal" },
                new int[] { R.id.lvnomor, R.id.lvperihal });
  
                setListAdapter(adapter);
  
           final ListView lv = getListView();
           lv.setTextFilterEnabled(true);
           lv.setOnItemClickListener(new OnItemClickListener() {
  
       public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
       @SuppressWarnings("unchecked")
       HashMap&lt;String, String&gt; o = (HashMap&lt;String, String&gt;)         lv.getItemAtPosition(position);
  
       no.setText(String.valueOf(o.get("nomor")));
       per.setText(String.valueOf(o.get("perihal")));
       surat_fi.setText(String.valueOf(o.get("surat")));
  
  
        Boolean result=isDownloadManagerAvailable(getApplicationContext());
        if (result)
        downloadFile();
      }
      });            
        }
      });
  
  
  @SuppressLint("NewApi")
  public void downloadFile() {
      String surfil = surat_fi.getText().toString();      
      String DownloadUrl = "http://link...";
      String fs = DownloadUrl+surfil;
      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fs));
      request.setDescription("Sedang download");
      request.setTitle(surfil);                
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
          }
          request.setDestinationInExternalFilesDir(getApplicationContext(),null, surfil);
  
           DownloadManager manager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
           manager.enqueue(request);
       }
  }   
  
  @SuppressLint("NewApi")
  public static boolean isDownloadManagerAvailable(Context context) {
      try {
          if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.GINGERBREAD) {
              return false;
          }
          Intent intent = new Intent(Intent.ACTION_MAIN);
          intent.addCategory(Intent.CATEGORY_LAUNCHER);
          intent.setClassName("com.android.providers.downloads.ui","com.android.providers.downloads.ui.DownloadList");
  
          List &lt;ResolveInfo&gt; list = context.getPackageManager().queryIntentActivities(intent,
          PackageManager.MATCH_DEFAULT_ONLY);
          return list.size() &gt; 0;
      } catch (Exception e) {
          return false; 
      }
  }     
  </code></pre>
  
  <p>and this is code to open PDF File :</p>
  
  <pre><code>String sur_fil = surat_fi.getText().toString();     
  String baca_file = "/sdcard/Android/data/com.e_office/files/";
  String fs_baca = baca_file+sur_fil;
  File pdfFile = new File(fs_baca); 
  if(pdfFile.exists()) {
      Uri path = Uri.fromFile(pdfFile); 
      Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
      pdfIntent.setDataAndType(path, "application/pdf");
      pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
      try {
          startActivity(pdfIntent);
      } catch(ActivityNotFoundException e) {
          Toast.makeText(SuratMasuk.this, "No Application available to view pdf", Toast.LENGTH_LONG).show(); 
      }
  }
  </code></pre>
  
  <p>Where should I put it ?</p>