0

I don't know how to write a code which check if pdf file exists and if it true, the another program open it. For example, my app user press on the button and then on the screen appears small GUI window with two selections : download PDF file or open it with another program. If user press "Open PDF" and pdf file isn't exists, it download automaticaly or on the screen appears a snackbar with text like: "You must to download file". Maybe you can write me a code or maybe it can be done easier? So, my problem - I don't know, how to write that program open a pdf file. Thanks! :)

iBoucher
  • 27
  • 4

1 Answers1

0

To open any file type you can use the particular Intent like below

                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.parse(path), "pdf");
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }catch (ActivityNotFoundException e){
                    e.printStackTrace();

                }

If user don't have any app to handle the pdf files it will enter into catch block and you can handle that case as well

Gautam
  • 3,252
  • 3
  • 23
  • 32