1

I'm new to programing and trying to open a pdf to view in my app. I'm not trying to include a reader "in" my app, but send it to what ever pdf reader the user has.

I've searched through all the questions here and found this one Render pdf.

I made a test app and it worked! The only problem is the end user has to save/launch the file from their SD card. I would like to include the PDF's "inside" the app.

So my question is:

  1. Where should I store the pdfs?
  2. How would I direct the app to them?

This is a snippet code for launching from the SD card, I would guess it's what needs changed:

public void onClick(View v)
{File file = new File    ("/sdcard/download/2011_BASIC.pdf"); 
Community
  • 1
  • 1
Niknjen
  • 21
  • 1
  • 5

2 Answers2

1

The files can be stored anywhere you want. Though you can achieve the thing that you want using the following code, it works for sure.

File openfile = new File(root+ file.getName());

Intent intent = new Intent(Intent.ACTION_VIEW);

Uri data = Uri.fromFile(openfile);

intent.setDataAndType(data,"application/pdf");

startActivity(intent);
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
PravinDodia
  • 3,271
  • 1
  • 18
  • 22
-1

Wow I can't believe no one answered this! I have found the answers my-self. I am posting them to help others and save them the time it took me to figure it out.

Question 1. The files should be stored in the /res/raw folder (make the folder if it is not there)

Question 2. The path is simply ("/app_name/pdf_name") quick note use %20 for spaces in the apps name.

-Nick

Niknjen
  • 21
  • 1
  • 5