3

In my app I am creating a pdf file in internal app files(data/data/package/files) I want these files to be readable when I read them using this code:

 Uri path = Uri.fromFile(pdfFile); 
 Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
 pdfIntent.setDataAndType(path, "application/pdf");
 pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

I have read about using openOutputStream() method but I have no clue how to read them through this.Could anyone help me?

EDIT

pdfFile--

    File    directory=getFilesDir();
    pdfFile=new File(directory,filename+".pdf"); 
Navdroid
  • 4,221
  • 7
  • 27
  • 47
  • have same problam http://stackoverflow.com/questions/10299839/how-to-read-pdf-in-my-android-application – MAC Apr 25 '12 at 09:05
  • what does your `pdfFile` string contain? – Pallavi Apr 25 '12 at 09:15
  • @Pallavi - File directory=getFilesDir(); pdfFile=new File(directory,filename+".pdf"); – Navdroid Apr 25 '12 at 09:57
  • `what does your pdfFile string contain?` meaning the value, when you write it in LogCat or some where... `pdfFile=/mnt/data/...` what is the value of the pdfFile variable? – Pallavi Apr 25 '12 at 11:02

2 Answers2

1

Pass MODE_WORLD_READABLE to openOutputStream() when writing the PDF to your internal storage. In theory, that will allow third party apps to read it.

Or, implement a ContentProvider for this file, such as the one I demonstrate in this sample project (here, copying a PDF from assets/ into internal storage).

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367
0

Add this:
pdfFile.setReadable(true, false);

Sami
  • 559
  • 3
  • 20