title: About opening .PDF in an Android App (locally stored)
body: <p>So I have these buttons in my app that I want to open .PDF files from within the application once pressed.</p>
  
  <p>I've stored my files in the /res/raw directory. Let's call them file1.PDF, file2.PDF etc.</p>
  
  <pre><code>public void onClick(View v) {
      switch (v.getId()) {
      case R.id.file1:
      Log.i(TAG, "Button one pressed");
      openPDF(Uri.parse("android:resource://test.pdf.files/raw/res/file1.PDF"));
          break;
  }}
  </code></pre>
  
  <p>Above is my code for the onClick. Underneath is the code for the openPDF function.</p>
  
  <pre><code>public void openPDF(Uri url)
  {
      File file = new File(url.toString());
      Log.i(TAG, url.toString());
      if (file.exists())
      { 
          Log.i(TAG, "File exists"); 
          Intent intent = new Intent();
           intent.setAction(android.content.Intent.ACTION_VIEW);
           intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           intent.setDataAndType(Uri.fromFile(file), "application/pdf");
           try
           {
                getApplicationContext().startActivity(intent); 
           }
           catch (ActivityNotFoundException e) 
           {
               Log.e(TAG,"Activity not found exception");
           }
      }else{
          Log.i(TAG,"404: File not found!");
      }
  }
  </code></pre>
  
  <p>My problem is as follows, I can never get past the if (file.exists()) check. I've tried making the File file take both Uri, URI and String, I have also tried more or less every variation of the filepath, like "res/raw/file1.PDF", "raw/file.PDF", "test.pdf.files/raw/res/file1.PDF". But in any of these cases I just can't find the file I want to open, can anyone see why this won't work? </p>
  
  <p>I have been trying to fix this for hours and hours and I just can't seem to wrap my head around it.</p>