0

I need to save PDF file when my app installs and then open it when a user clicks on a button. I found many solutions but was not able to integrate them into one.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rahul Kumar
  • 99
  • 3
  • 10
  • 1
    You need to add some more detail then. What solutions were you not able to integrate? Did you try using intents? – StephenG Jul 22 '15 at 20:26
  • I found in one of the answers that I have to keep the pdf file in res/raw folder during compile time and then it will get into the device during installation. After that I can use it using Resources.openRawResource() with the resource ID, which is R.raw.filename. But it is not working for me. – Rahul Kumar Jul 22 '15 at 20:30
  • No, I haven't tried using intents. – Rahul Kumar Jul 22 '15 at 20:31

2 Answers2

1

Try this code, display pdf file from a file location (works from any file location, not SDcard specific)

How to open a PDF via Intent from SD card

Community
  • 1
  • 1
StephenG
  • 2,851
  • 1
  • 16
  • 36
0

I was doing this in work today and it is not that easy.

1) saving the file is not difficult any normal file code will work for a pdf file.

2) showing the pdf you have two options you can display a pdf in a webview if the device has internet access by displaying a Webview and loading google docs with you pdf file at the end of the url

3) or you can create an intent and see if the device has an application that will display the file, you will need to use a FileProvider to get it to run but there is a good post

https://developer.android.com/reference/android/support/v4/content/FileProvider.html

Mark Gilchrist
  • 1,972
  • 3
  • 24
  • 44