3

Hey I am new in android I have a requirement to choose pdf files using Intent. I am using this code to set type of MIME.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("pdf/*")

But it's not working the way I want, please provide me any suggestions or can I make some changes to the existing code.

Dhaval Patel
  • 10,119
  • 5
  • 43
  • 46
Vivek Pratap Singh
  • 1,564
  • 16
  • 26

2 Answers2

5

Do this intent.setType("application/pdf");

Dhaval Patel
  • 10,119
  • 5
  • 43
  • 46
dex
  • 5,182
  • 1
  • 23
  • 41
  • how to open only word file via intent?? – Reprator Mar 29 '16 at 07:58
  • just set the mime type for the word file for example for .docx file mime type will be : application/vnd.openxmlformats-officedocument.wordprocessingml.document so intent.setType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); – dex Mar 29 '16 at 08:38
  • Microsoft Office MIME types are given here http://stackoverflow.com/questions/4212861/what-is-a-correct-mime-type-for-docx-pptx-etc – dex Mar 29 '16 at 08:39
  • My system's file picker shows Google Drive as a provider. If I click Drive, I can select a non-PDF file. How to get around this besides eliminating Drive entirely by using EXTRA_LOCAL_ONLY? – B W May 30 '17 at 17:12
4

Try Below Code:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
Kishan Soni
  • 816
  • 1
  • 6
  • 19