0

So in my Eclipse android project I have a pdf file that I'd like to open, I looked up the standard address on the android developer's page and I came up with this pointer:

File file = new File("Android/data/com.alex.testing.app/res/raw/jazz.pdf");

where jazz.pdf is situated in res->raw in my eclipse project, and com.alex.testing is my package name.

Still, when I try if(file.exists()) , the function returns false (on the emulator it goes to an else I've set up to display an error message)...

Sorry for the newbie question, but I'm really stuck with this :(.

Matt
  • 22,721
  • 17
  • 71
  • 112
user1123530
  • 561
  • 3
  • 7
  • 17

3 Answers3

1

put the file in assets folder and pick the file from there

Now use Context.getAssets().open("jazz.pdf") and pass the resulting InputStream into PDf parser library

ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
0

//if your are stored in SDcard your location would be

"data/data/com.alex.testing/res/raw/jazz.pdf"

//you read resources from raw folder thru the below code

InputStream inputStream = getResources().openRawResource(R.raw.jazz);
byte[] reader = new byte[inputStream.available()];
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
0

Ok, to access resources from current application you can use something like,

Uri path = Uri.parse("android.resource://<you package>/raw/<your_file.pdf>");

OR

Uri path = Uri.parse("android.resource://" + getPackageName() + "/" R.raw.<your_file.pdf>);

But I have a doubt if you are trying to use this pdf file in your application then its OK, but If you want to view this file using any third party application then I think you can't do it.

Because external application can't access application's package resources file.

So better way it to put this file in /asset directory then copy it to any public access area then view that file from that path.

user370305
  • 108,599
  • 23
  • 164
  • 151
  • Thanks, I've tried [this](http://stackoverflow.com/questions/4447477/android-how-to-copy-files-in-assets-to-sdcard), I'm trying to open the file with the Adobe reader app, but it gives me an error, "The file could not be opened.". Also, when I check with the fileviewer /sdcard/ , there's nothing there... what am I doing wrong? :-? Currently I'm using Yoram Cohen's code. – user1123530 Mar 06 '12 at 22:57