How to make a PDF file in my APP’s Assets open by the android’s native PDF reader?

Asked

Viewed 99 times

-1

I have an APP that needs to open some PDF files (laws) that should come along with the application.

The idea is to call an Intent to open these PDF files by Android’s own native PDF reader or a PDF reader already installed on mobile. The files are in the Assets (inside the res directory). How do I open the external PDF reader application and intend to open the PDF with the file path that is on Assets?

I’ve tried a lot of things, and I haven’t been able to. Please help me out!

  • Do you have any code that you can show to give more details?

  • It would be like the APP Firefighters IT-Technical Instructions (It opens the legislation in a PDF viewer where it has PDF reader’s own search field).

1 answer

0

file://android_asset is visible only to your app. You’re wanting another app to open a folder file assets that he does not possess.

What you can do is copy this file to the internal or external directory and then try to read the same.

  • That’s right. You have some code like this?

  • Something like this: https://gist.github.com/alhazmy13/c93c5e083ec0b7fe6d1c

  • Do not forget the permissions of READ and WRITE

  • I think that’s it. But what would my xml look like?

  • <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

  • In the example you gave me, how do I call the openPDFFiles method (As reported in item 5)?

  • openPDFFiles("file.pdf")

  • Wow, by clicking the button it triggers the PDF reader and then back to the APP with the following message: Could not access the file. Check the location or network and try again.

  • I asked another question with the code at the following link: https://answall.com/questions/309949/como-abrir-um-arquivo-pdf-que-esta-no-assets-do-meu-app-em-um-leitor-de-pdf-j%C3%A1

  • Sorry to bother you, but please check what I did wrong.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.