Limitations on opening pdf file in Android

前端 未结 6 1489
暗喜
暗喜 2021-02-11 15:04

I am trying to opening some pdf from my Android application. I am using an Intent for doing that:

Intent intent = new Intent();
intent.setDataAndType(Uri.parse(u         


        
6条回答
  •  终归单人心
    2021-02-11 15:51

    I found a workaround to view my PDF on my Android application (but does not allow me to download it after show on the application). If I open my PDF using Google Docs I can open it with my Intent.

    This is what I had to add before my url:

    https://docs.google.com/gview?embedded=true&url=
    

    so the final url will be like:

    https://docs.google.com/gview?embedded=true&url=https://myUrl.pdf
    

    Here is the whole code I am using right now:

    String url= "https://docs.google.com/gview?embedded=true&url=https://url.pdf";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    

    But it is still not enough, because I would like to open it without need of using a third party application. Also, opening PDF with Google Docs is slow and I have to wait too much until the PDF is finally opened.

    If anyone knows how to open it with native Android please let me know.


    What happens if I do not open it with Google Docs?

    With the same code, but just using my url, instead the added Google Docs url, Android let me choose between two applications: Adobe Acrobat Reader and Google Chrome.

    • If I open it with Google Chrome it download the PDF but it is not opened automatically.

    • If I open it with Adobe Acrobat Reader, it gives to me the following error:

      The PDF cannot be shown (it cannot be opened)

提交回复
热议问题