Android: open pdf file with the specified software

Now I have downloaded the .pdf file from the website and want to open it using the specified software , for example " Adobe Reader ". How can i achieve this? Thanks in advance!

+4
source share
3 answers

I solved this problem by adding the method " Intent.setComponent(pkg,cls); ". PS: I'm not angry at knocking down my turnips. And thanks for giving me suggestions. PSS: I want to say: "Not everyone will get the same apple." I am posting this question because I have this problem and it happened in an Android app. And someone told me, "I can’t." I am sending my answer to inform you that I have solved this (or just my) problem, and maybe this will help someone who has the same problem as mine. Yes, this answer may not make any sense to you. PSSS: :-) But I still think the API is understandable for me and for my Designer. * PSSSS: * Finally, thanks to everyone. And forgive my bad English.

+2
source

You can not. All you can do is hide the intention and let the system handle it. If the user already has the default application that they have selected for processing PDF files, this is the one that will open the PDF file.

In general, this is something like:

 File file = new File("/sdcard/example.pdf"); if (file.exists()) { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } ....... 
+2
source

First of all, you should take a look at intents filters documentation . Then you can start the intent (after adding the intent filter) for your PDF file.

+1
source

Source: https://habr.com/ru/post/1381418/


All Articles