0

I tried to open pdf using pdf reader. but im getting no application found.

how can i find is there any application available before showing the message.

I want to open the application popup only if any application exist to open the pdf file how can i add it?

Intent target = new Intent();
target.setType("application/pdf");
target.setData(Uri.parse(attachment));
target.setAction(Intent.ACTION_GET_CONTENT);
Intent intent = Intent.createChooser(target, "Open File");
Rakesh
  • 55
  • 2
  • 9
  • Look at this: https://stackoverflow.com/questions/15407502/how-to-check-if-an-intent-can-be-handled-from-some-activity – Krupa Kakkad Aug 25 '17 at 09:38

1 Answers1

0

Try this;

 Uri path = Uri.fromFile(file); 
 Intent intent = new Intent(Intent.ACTION_VIEW); 
 intent.setDataAndType(Uri.parse(attachment), "application/pdf"); 
 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

 try { 
      startActivity(intent); 
   }  
    catch (ActivityNotFoundException e) { 
       Toast.makeText(OpenPdf.this,  "No Application Available to View PDF",  
                        Toast.LENGTH_SHORT).show(); 
   } 
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57